Is there anyway to let the AI get information from class variables in Unreal?

Original Discord Post by phoenifox. | 2024-08-29 07:22:30

If I created some variables in the AI Character class. For example, AI Character named Jack has a float variable ‘Cash’ represents how many cash on him. Is there anyway to let the AI get the variable and tell me the value of the variable?

Reply by phoenifox. | 2024-08-29 07:29:25

I do have a solution in my mind and tried it, it works. I know the AI character can get information from Objects and characters in enviroment. So I created an actor in world add added it to the AI’s Object list. I named the actor as ‘Jack’s Information’. And for the information of the actor, I added ‘This is Jack’s Information. He got 1000 cash on him, and he has a lollipop on him.’. After done that, the character can tell me how much cash on him and when I ask what else on him, he also answered that he got a lollipop. It works, but I want know if there are a better way to do it.

Reply by mighty_brute | 2024-08-29 07:59:57

Hello <@306798908116303892>,
You’ve found a clever workaround! Instead of creating and managing a new actor, you could use setters for the variables you want your AI character to access. Update the values directly and call the AddObject function from the environment. This way, your AI character will be automatically updated whenever the value changes, and you won’t need an extra actor. Check the screenshot for reference.

Images:

Replying to mighty_brute’s Message

Reply by mighty_brute | 2024-08-29 07:59:57
Hello <@306798908116303892>,
You’ve found a clever workaround! Instead of creating and managing a new actor, you could use setters for the variables you want your AI character to access. Update the values directly and call the AddObject function from the environment. This way, your AI character will be automatically updated whenever the value changes, and you won’t need an extra actor. Check the screenshot for reference.

Reply by phoenifox. | 2024-08-29 08:42:23

Hi Brute, thank you a lot for your answer :D. It works well! I created a setter like you did and it successfully initialize the cash count for the AI. But a new question appears in my mind. Can I update the cash variables by talking to AI like, “I’ll give you 500 dollars.” I tried to create a Take Cash event to do that, by using the Setter to update the cash variable. But I find that I have no idea to get the input value for the Setter.

Reply by mighty_brute | 2024-08-29 11:22:49

Based on certain events, you can pass values to the setter function, for example, using a key trigger. Then, you can use the InvokeSpeech function to make the AI character speak about it.

Additionally, you can use NarrativeTemplateKeys for this. To learn more about NarrativeTemplateKeys, you can refer to this Documentation.

Replying to mighty_brute’s Message

Reply by mighty_brute | 2024-08-29 11:22:49
Based on certain events, you can pass values to the setter function, for example, using a key trigger. Then, you can use the InvokeSpeech function to make the AI character speak about it.

Additionally, you can use NarrativeTemplateKeys for this. To learn more about NarrativeTemplateKeys, you can refer to this Documentation.

Reply by phoenifox. | 2024-08-29 11:32:52

Thank you Brute, it is really useful. I’ll check the document and learn how to use it. :grin:

Reply by mighty_brute | 2024-08-29 11:33:42

If you have any other questions, please do not hesitate to ask.

We would be very grateful if you could leave a comment on our store pages with your company name or the name of your project. We value your feedback and comments as they help us improve our services and products.
https://www.unrealengine.com/marketplace/en-US/product/convai/reviews

Embedded Content:
AI for NPC, MetaHuman - Dialog, actions and general intelligence - …
Convai powers NPCs with human-like intelligence.
Link: https://www.unrealengine.com/marketplace/en-US/product/convai/reviews

Reply by phoenifox. | 2024-08-29 11:37:50

I will, Thank you :grin: <:OK:1147889183776587778>

Reply by phoenifox. | 2024-08-29 11:43:16

Hmmm, I didn’t see the solved tag there, should I just close the post? <@1216254232957685765>

Images:

Reply by mighty_brute | 2024-08-29 11:43:53

I’ll do that

This conversation happened on the Convai Discord Server, so this post will be closed.