How AI can get actor's variables (i.e. health)?

Hello!

Sorry, if I haven’t found the existing answer, but I was trying hard to. I’m very beginner in UE4 and programming also.

I’m trying to make a AI’s world, where they interact only with each other (not with player). So I want to spawn the same AI actors and let them Pawn Sense each other. I’ve found how to get “Pawn” out of “On See Pawn”. But how to make AI_001 get AI_002’s variables, such as health, mana, age, whatever? And how to make sure that i’m getting AI_001’s variable, not AI_001?

I guess I need to assosiate “On See Pawn” with variable, i.e. “Health”, and use only variable that is assosiated with particular Pawn’s actor.

Thanks in advance!

To get the attributes of the other
pawn in your sceen, you just have to
get the sensed pawn, use the ‘cast to’
node to cast to your ai pawn. From the
return value of your cast, you can get
the health of your sensed pawn

Am I doing that right?

To be hones I don’t really understand what “Cast To” is and how to properly use it.

Thank you for the plugin advice, I’ll try to figure that out.

Hi!
I can really recomend you a free plugin from the marketplace, it is called Faction Extension plugin. Its a great and easy to use plugin for setting up factions. You can use it to tell your Ai who is friend or foe.

To get the attributes of the other pawn in your sceen, you just have to get the sensed pawn, use the ‘cast to’ node to cast to your ai pawn. From the return value of your cast, you can get the health of your sensed pawn

I hope it was helpfull, if you need further help, or images of the setup, just let me know

Well, in this case with casting you are checking, if the pawn you see is the bot_1 if it is, its going to fire from the top pin, and return the health value. If its not the bot_1, its going to fire from the cast failed

i like to think of a cast as identifier, it basically asks is the object in like the class im comparing it to. theres actually more to it where you will learn that its based on inheritance and checking if the object inherits from the class your looking for.

so heres the real questions, what class are your ai? are they of the same class? if they are all of the same class then you can just cast to that class. if they are not of the same class then they wont contain the same variable types. this means you will either need to do a cast for each class or place the variables in a class they all inherit from.

inheritance is a tree structure where many classes can inherit from one. a child in the tree will posses all the features / attributes of the parent and then adds its own functionality on top of it. i personally like the car analogy to explain this. a ford mustang class would be a child of the car class since it inherits all the attributes of a car; four wheels, basic shape, etc. in turn car would be a child of vehicle, moves things from place to place, complex machine, etc. in the engine there is examples of this as well character inherits from pawn, pawn from actor, actor from object. so this means you can create your own class which inherits from character, then another class which inherits from the first one you created. in this way you could put a variable such as health in a parent class and all the children would then have it as well. what this means for your case is that if you have many enemy types that are all their own class but they inherit from a common class then you can cast to the class they have in common. this may seem a bit confusing but with more experience youll understand.

I’ve just realized that my answer didn’t update. Thank you very much, that really helped me!