Brain fade and need help. Get - Cast to ...

Hi

Can someone post what I need to do to get a variable frm another blueprint.

I had a feeling to was

Node - Get - Cast to…- promote to Variable

What is the first node? Complete brain fade

Make sure your variable is public, then have your blueprint as a variable from which to cast from.
As below

Here “Selected Player” is an actor of the same type, which I casts to the blueprint I want to get variable from.

the first node is probably a variable/reference to an instance of the BP you want to get the other variable from…

(GET ChildThingy)—>(GET TheVariableIWasLookingForInTheChildThingy)—><do stuff>

more or less xD

You have first make sure the variable is exposed by clicking the eye symbol found to the right of the variable, then it should be accessible. Typically, if I was trying to access a variable from my character whilst in my level bp, I would do the following…

Get Player Character -> Cast to My Character -> (As My Character) Get My Variable

I was too late, it’s already been answered :slight_smile:

Hello,

It depends on what kind of Blueprint you want to retrieve a variable from. If its from the character for example you’ll want to create a “Get Player Pawn Controller” and then Cast To… to your character BP.
If its for a normal actor BP you’ll want to “Get Actors of Class” and select that BP’s name as Class in the node. Then if you want to Cast to a specific one (if you have more than one) you’ll have to make a For Loop and look for the one you want (being it the one closer to your character or w/e) and from the returned index value of the For Loop, you make the Cast To…
From the Cast To node you can then call to whatever variable you’re looking for.

I think that’s it. If i recall that’s you need. Maybe i’m forgetting something because lately i’m getting pretty rusty with ue4 without using it as much as i’d like to :stuck_out_tongue:

Edit: when i started writing it had 0 replies. I’m really slow haha

This is the blueprint I want to call

Capture.JPG

When I go to another BP

Capture.JPG

So I do not need to “GET” in 4.7 anymore?

P.S. Thanks for the replies

Any reason why this would not be calling.

Hmm sorry but i can’t help you out with 4.7 :(. I’m still using 4.5.1. And in there i can be almost sure that this setup of yours wouldn’t work as you’d have to connect something to the “” pin in the Cast To node. Like that you’d only get the first instance placed on the map i think.

Hooked up a reference. Got a loop error. May need to look into further.

I wanted was if the Mesh was in play, it would add to the the "World "

Should I just do it in each BP and ignore this function in World BP

If your are in level BP you don’t have to Cast To i think. You should be ok with just the reference. I’m not to used to work with level BP tho but i think the “get reference to” node in level BP is specific to the instace selected in your level so you don’t want to make a Cast To out of that.

If what you want to do is look at every instance of you BP in your level and take a look at it’s “Alive” variable, then you have to make a For Loop. You first want to “Get Actors of Class” and from there make a ForLoop, here you’ll want to Cast To every one of them based on the index of the ForLoop and then in there you’ll check for it’s var’s value and make w/e code you want in there.

A little new to For Loops.

The first index should always be 0, and for testing proposes I only want one out. Should the Last index be 1 or 0.

And why would this become “Dead” and if I put the same nodes in the BP it comes up alive?

Cheers

Oops! sorry my bad. I did a mistake, i didn’t meant “ForLoop” node but “ForEachLoop” node to get the values directly from the “Get Actors of Class”’ array.

&stc=1

The branch node part is just for testing to get only the print if the index returned is = to 0, i.e. only the first returned element. This should print “Alive” always as long as you have that:

Capture.JPG&d=1421671902

in your Building_1_StaticMesh Blueprint.

I hope this helps.

EDIT:
Please be careful! If you set that arrange of nodes on your Level Blueprint. You’ll get “Dead” as the printer string. This is because the “Begin Play” event is executed first in your Level Blueprint then is executed in the rest of BPs. You can fix that by adding a default value for your “Alive” variable of “true” or just adding a “Delay” in your Level Blueprint’s Begin Play event node (between this node and the “Get Actors of Class” one)

I have set it up the way you have. Except the it fires false unless I have a delay (Not an issue) and not put the Array Index in to the Branch but the Alive BOOL

I set a branch up at the end to confirm still alive and then looped back to the delay.

Does this seem right?

Regards

Well yeah i just set that branch there to limit the print node to just the first index in the ForEachLoop.

Got it. It works.

Put 2 meshes down and destroyed them on overlap. Counter stopped.

Thanks you.

  • Edit *

Sorted

Thanks for the help.

You’re welcome!

I’m glad you made it ^^. If you have any other question just ask.