x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: UE 4.20
Tags:
more ▼

asked Oct 06 '18 at 06:35 AM in Blueprint Scripting

avatar image

RoKoFo
8 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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

more ▼

answered Oct 06 '18 at 08:33 AM

avatar image

Evertoo
124 2 3 5

avatar image RoKoFo Oct 06 '18 at 09:39 AM

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? alt text 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.

castto.jpg (32.9 kB)
avatar image ThompsonN13 Oct 06 '18 at 01:30 PM

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.

avatar image RoKoFo Oct 25 '18 at 01:08 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Oct 06 '18 at 11:50 AM

avatar image

Evertoo
124 2 3 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question