Communicating between spawned Actor and Blueprint

Hello,

I’ve been stuck on the communications part of blueprint for a little while now…

Basically, during the game there is an actor that spawns. You click on it and it gets destroyed.

There’s a variable that increments each time you click the actor.

I managed to get it to work somehow on a previous iteration using a HUD blueprint(MyHUD_test) and the spawned actor blueprint(Aproj).
This is how it worked:

31994-myhud_hitcount.png

Now I’m UMG and can’t seem to find a way to communicate, simply, between my spawned blueprint and other UMG and/or other blueprints.

How can I get my spawned actor to communicate with the rest ?

I assume you spawn your widget in your controller right?

And I further assume you handle the clicking there as well. If both are true then you can when creating the widget save it in a variable and if you hit one of those actors you can either add a hit count from your controller if the destroying of the actor was successful (use an interface to do some logic inside of your Apoj actor and return a bool for handling there) or just pass down your widget via an interface and do all the logic in your apoj actor. Once you have that variable you can increase the hitcount.

Small tip: Don’t save gameplay variables in your widgets / HUD. Keep those together either in your character, controller, game state, player state or even game mode if it has something to do with it. It’s easier to find them if they are all in the same place and you can’t lose them when changing the widget.

Cheers

Hello,

Thank you for the reply.

The actor I’m spawning is just a simple projectile cube.
(it spawn by clicking on another actor)

32160-targetcube_spawn.png

I’ve got the communication part working to an extent.
My click/count function is this:

32155-increment_functioncall.png

And it works, yay !
But then if I miss the target and it “escapes”, adding a function for that scenario:

Then the incrementation doesn’t work that well anymore, neither does the decrementation system…

32158-gamemode_countfunctions.png

When exiting the triggerbox it counts double, well -2 instead of -1, and when clicking to spawn another cube it just adds +1 instead of the +3…

I was wondering if this is happening because the spawning takes place inside the Triggerbox ?
(I’ll have to test it)…

This is certainly strange. Have you looked on the graph what happens during gameplay?

First of all (for clarity) I would put the destroy actor behind everything you want to execute (in this case “Target Escaped”). In other languages the very last thing you can do with a class is removing / destroying it and it just feels like this should break there. Epic probably caught this type of mistake and just do the correct thing anyway but still…

And then just for testing purpose I would try a “Do Once” node right after your trigger cast so in case it’s called twice it won’t execute a second time. If this fixes the -2 it is caused by some weird interactions with multiple overlap events. Otherwise you have another function somewhere writing to that value.

While you’re at it check as well if your “Target hit” function is also triggering the “TargetEscaped”. This would explain why it’s only adding 1. This can happen if you don’t instantly destroy the actor (which you are not) and since it then sill triggers the “End overlap” it will call that as well.

Cheers

Hello again,

So I tested the Triggerbox thing and found out why it triggered the “TargetEscaped” while clicking… Normally, after the “TargetHit” function there’s the destroy actor function(not shown in the example above).

And because the spawning/clicking/other(?) was happening inside the triggerbox, I guess that by destroying it, it “exited” the triggerbox and ended up calling the function… :confused:

By placing the triggerbox elsewhere the TargeHit function worked nicely.

Finally, the DoOnce node did help after the triggerbox cast, otherwise it still decrements twice.

So thanks for the help, it’s very much appreciated.

“Cheers”

ps: Do you happen to know of an overlap event that’s triggered on “full overlap”, not begin/end ?


(little “noob” question how/which part of this do I tag as “answered” ?)

I’m not sure how a full overlap can be checked… you could try checking for all components if they overlap but they still don’t need to fully overlap in order for this to return true. In general depending on the requirement I would probably just make the volume smaller by the capsule radius and just check for that one…

To your “noob” question :smiley: Well I only answered once. Comments can’t be accepted as answer but can “only” get a thumbs up.

The button to mark it as resolved is right below the vote arrows of the answer.

(answer’s up above…)