Download

C++ how to set variable on actor

Hello guys, I have a AI blueprint wich inherited from c++ code, and it has a variable - health, I’m doing a line trace check via c++ and want to know how to decrease health variable when I hit an actor/character. In blueprint I would just cast to that class and set variable, thank you :slight_smile:

You do the same thing in C++:

Here’s some spicy pseudo:



// The actor that we hit is casted to YourAICharacter
YourAICharacter ai = Cast<YourAICharacter>(HitActor);

// And we reduce the health
ai->DecrementHealth(damage);


Thanks that makes sense mate ^^ So we have to call an actual function to decrease health, and what if AI was blueprint only with no c++ code? Would I have to make a function in blueprints to do same thing? :slight_smile: