Get a variable from not yet spawned object

Hello,

I’m new to blueprints and don’t understand how to make a variable global.
I tried to use blueprint interfaces, but quite don’t understand it. :confused:

What I’m trying to do:

→ A spawned object adds 1 to an integer variable, saves this variable for himself.
→ A new spawned object uses the new integer variable and also add 1 and saves this varaible for himself.
→ Now if the two actors hits each other I want to compare those two integers the one with the higher integer should be parented.
→ And so on.

I want to learn how to use Interfaces or how to pass a variable for this exact case.
If anyone could explain it step by step how to do this I would really appreciate it. :slight_smile:

Just a thought, but why not have whatever spawns the object set the variable right after is spawns it. Whatever object does the spawning has the “global” count and assigns it to a individual object.

And how do I assign the numbers to the objects?

if the object has a variable you can click the eyeball next to variable in it’s blueprint. That makes it public. Then, after you spawn it you can drag out a reference to the public variable and call set on it.

Ok, but how do I compare those in EventHit? (If I have 20 spawned objects for example)

the hit will be in the object itself and will have reference to the instigator. just cast it to your object type.

I hope its not to much to ask, but could you show me an image of the nodes, I’m not really understanding how casting works.
I can’t seem to cast anything to my custom BPs.

EDIT:
Oh well … now I can pull casting out of the reference … nevermind.

EDIT:
Finally got it working!

Try this. I’m not sure if this is the kind of parent you wanted but it explains casting and getting variables from other objects.

Yup, thanks for the help! :slight_smile:

No problem. Don’t forget to mark the question as answered. It helps epic got to other questions faster.