Download

How to access a variable from the level blueprint?

I’ve got a bool in my level blueprint which I want to reference in a blueprint for a door which will start working when the bool it’s getting is true. Just need to be able to get the variable into the door blueprint and I can’t find any way to do it.

click on your bp , add a reference to it in level then cast it to your Door bp then get you boolean from the cast result

I found a work around. Instead of trying to access the variable from the level blueprint I put it in the blueprint I wanted it to be used in and then made a variable of that blueprint then referenced it in the level blueprint instead.

Okay, it doesn’t work as expected. I can get the variable into the level blueprint but during runtime it says the variable is out of scope. Even though I made it a public variable. I don’t know how to even get a ‘cast to’ function from the context menu or what type of node I can use to get one! I mean I’ve got a reference to my door BP in my level blueprint but the ‘cast to’ doesn’t appear on the list.

In order to get a “CastTo” function you need to draw a wire from an Object reference (or a reference of an object of any class that derives from Object, such as Actor) node and then type “CastTo”. You will get all available options for you to cast (if you use an Object variable, you’ll get CastTo to any class that derives from Object class; if you use an Actor variable, you’ll get CastTo to any class that derives from Actor, and so on…).

In order to pass a bool from the level blueprint to a class blueprint, you can try creating a custom event (let’s call it “ShareBool” for example) in your class blueprint and adding a Bool input to it. Then, from the level blueprint, call that custom event simply by dragging a wire out of your reference in the level blueprint and typing “ShareBool” in the search box. Feed your Bool variable into it.

Then, back in the class blueprint, create a Bool variable (let’s call it ReceivedBool), go to your custom event ShareBool and, from it, set the ReceivedBool variable to the Bool that you obtained from your level blueprint. This way you should be able to trace its value at runtime.

24577ce8e6fdc84464b3a0d8426bf04541e5a3cf.png

See, there is no castto function.

Of course, because there are (presumably) no classes that derive from your LockedDoor, unless you yourself created one that does. If you want to test the CastTo function, create an Actor variable, get it in the blueprint and try again.

If what you want is just to pass the bool, you don’t need a CastTo anyway, just your LockedDoor reference will do for calling the custom event.

You’d think so but I can get the variable from it yet it doesn’t change the value of the bool during runtime. It says it’s out of scope even though I’ve clearly got it through a reference, AND I set it as public too. :

Here’s what I mean:

Class BP (in this case, your locked door):

ClassBP.PNG

Level BP:

LevelBP.PNG

(Don’t pay attention to the “Target is ObjetoRecogible”, I just used an already created Class BP from my own project, for this example. In your case, as you have created the ShareBool event inside your LockedDoor class BP, you will see "Target is LockedDoor).

check context sensitive , then cast it to your “Door BP” then get your function or variable from " As ‘your door BP’ C"

Thanks for your help. I’ve done everything except being able to find the bool from the Class BP. I’ve had to drag from the Class BP reference and then I can get and set unlocked.

I’ve now realised you used a seperate bool for your Level BP which I have now fixed but… in the class BP when I go to set the bool there is no tick box to set it to true. I see how this works now, I found it hard to understand orginally but it’s like a mole tunnel. You weave a bool from Level BP through to the class BP and then set the class’s bool using the ‘fake’ one.

That is normal, it is because, for the bool (StoredBool) in the class BP, you are using the bool you fed it from your level BP to set its value. What you have to make sure of is that your Level BP Bool (in my example, MyLevelBPBool) has the value that you want when you pass it to the class BP.

Ahhhh, I get it! Thank you very much for all your help :-))

It’s no problem. Good luck with your project :).