Get a boolean from another actor's component

Heya, I am having difficulty figuring out how to get my player character actor to read information from my an actor component blueprint that is a part of an enemy actor. The specifics are that I have a damage system component on both actors that contains variables like health and if an actor is dead or not, I am trying to check if the enemy actor is dead or not when a certain event fires on my character actor, but I do not know how to access my enemy actor’s version of the damage system component, which is where the isdead boolean for the enemy actor is stored.

Thank you, please feel free to ask for more detail if it can help.

1 Like

Hello @LegionDivided27 ! :slightly_smiling_face:

If you want to use a variable of a bp inside another bp, you need to get its bp’s ref first. There’re different ways to do so, but, some of these are performance friendly, other methods not so much.
You can try, for example, via blueprint interface/event dispatcher.

1 Like

@LegionDivided27 Get the actor bp first using ‘Get all actors of class’, then from the array ‘Get (a copy)’, then get your variable out of the copy.

Note: The integer in the ‘Get’ node stands for the components in your other bp and begins from 0

2 Likes

It’s not so recommended, it depends. Because if he need a specific ref, for a specific use, for example, this way is risky. And also, if he has a lot of bps spawning/destroyng in run time and he does once get all actor of class, it could iterate on references that are no longer valid, on situations that are not updated, and doing “get all actors of class” with a tick in run time, is not good for performance.

You need to get a reference to that actor,being it’s a combat system I’d think a collision event would be the best way. Say for example your shooting a projectile, on the projectiles hit(or overlap event), get overlap actor from pin, cast to class of enemy, get the component, then get the variable. From here you can take necessary actions. Hope this helps.

1 Like

I already have a good reference to the actor in question, I have a collision sphere around the player that adds and removes the actors in range (only those with a “targetable” tag) to an array and the enemy actor in question is also stored in the players “TargetedEnemy” variable.

Is it safe to just get the component from the actor reference with “get component of class” and just get the variable directly from the component similar to what kenneth has demonstrated? or is it better to make some kind of event to get that variable? I have the damagesystem component containing the isdead variable as a part of my player character actor too and I want to get the enemy actor’s isdead, not my players.

Thank you, this already helpful.

edit:


Is this image a good solution?

after getting the reference of the actor you have to cast it to the actor class of choice (e.g EnemyActor or something like that) after that try calling Get [Component Name] it should give you the component reference like HealthComp (look at the target actor’s component list and find the name)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.