Access Variables From Another Actor When Overlapped

Hi, I’m having an issue understanding what I think is a very simple problem. I am trying to have an actor with an On Overlap event be able to manipulate the variables of another actor, but the actor may be dynamically spawned in.

To go more in-depth, this is for a side-scroller(ish) platformer game. I have my player character able to left-click to spawn a “hit zone” that is adjusted based on the player’s level and stat variables with some minor variance (not so important). So when the Spawn Actor node is used, it spawns a BP_AreaHit blueprint that pulses X amount of times doing Y things and applying Z status effect. The problem is, what I want to do is get a list of the overlapped actors (which I do with For Each Loop and Get Overlapping Actors), determine which are enemies (tag isEnemy), which are environmental objects by type (tags isWood, isStone, isMetal), and then I want to call events in that actor and pass variables onto them.

Currently, I have an Event Begin Play connected to a For Each Loop to go through the Get Overlapping Actors array and go off branching nodes to see if it contains the different tags, and if so at the moment it just does a Print saying what the tag it overlapped with is, then it repeats on a .15 second delay for X number of times before Destroying itself. This is working just fine, it’s printing the right tags, and even as actors move into or out of its Overlap (effective area) it prints the correct Tags for that moment, so I can differentiate that it is able to do different things for different Tagged actors.

The problem I have is that not all isWood or isMetal (and especially not all isEnemy) Actors will share the same Parent BP. So, going off of just the fact that an overlapped actor has a specific tag, how can I say, “call an event that I assume all actors that can be hit will have, and change these variables that I assume this hit actor will have to these other variables’ values of the player character’s stats?” I’ve seen people say “Cast To Actor,” but how can I cast a custom event and the variables to the overlapped actor?

I’m sorry if this isn’t very clear, but I need Actor A that spawns Actor B to be able to apply X Y and Z variables to any actor that B overlaps who has a specific tag. Any help or pointing me in the right direction is GREATLY appreciated, thank you!

I’m not quite sure what’s overlapping what there, but when an overlap occurs, you get an actor reference

image

you can cast to your of your wood/metal BP and call custom events, or you can cast to the parent of your other types and do the same.

The problem with using casting to know what kind of actor is passing by means you have to cast to all the parent types to figure out what’s going on. You also have to ‘reach in’ to those other actors to call the custom events or tweak variables, which is bad practice.

A much better approach is blueprint interfaces.

With BPIs it doesn’t matter what’s just overlapped, you can call the same interface on everyting :slight_smile:

image

( Send is not an engine thing, it’s the name of one of my BPI functions ).

Then, it’s up to the receiving actor to decide how it implements ‘Send’. The implementation can be different in all actor types. It also means you can ask to have variables etc changed in the actor, without knowing how that happens.

2 Likes

Thanks! I’m gonna get on this. My workaround since has been to use essentially a global handler and then pull it up as a reference with inputs to decide what it does. This…seems MUCH better, and I’m astounded I never came across it. Thank you.

1 Like