Why Can't I Access A Variable From Another Blueprint

Basically I have one class that detects when the game ends and sets a GameOver bool to be true. I want my other classes to see this variable and if it is true, stop what they’re doing, playing music/spawning objects/moving etc. This should be simple but it seems needlessly complicated in Unreal. I’ve seen multiple questions asked about the topic with no satisfactory answers.

Hey CBFlood-

What type of blueprint is the one that sets the GameOver bool? Is it an actor, GameMode, Character, etc.? Though most of the steps are similar there are a few differences in the setup you’re looking for based on the type of blueprint being called.

Assuming the reference to the object that contains the GameOver bool is of the correct type, you should be able to find “Get GameOver” and “Set GameOver” nodes if GameOver is set to public visibility.

You can change a variables public visibility under the My Blueprint tab of your blueprint, towards the right side after your “GameOver” variable there should be a little icon of a closed eye. If you click it it should change to an open eye. signifying that the variable is publicly visible.

24300-uepublicvar.png

If however type you are referencing the variable from is of the wrong type, you’d want to cast it to the correct type you can do that by using the “Cast to MyBlueprintType” node.

Edit: Also, as mentioned, how you get that initial reference to your specific class changes based off of what type of blueprint you are creating, and how it’s being used. But otherwise the steps should be widely the same.

I’ve used this tutorial https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/BlueprintComms/index.html which I think is what you’re suggesting. It works now when it didn’t for the entire week, I have no idea why, I’m literally using the same variables. However the get methods only seem to work. If I try setting it in another class the set just doesn’t change it for the other classes. It must be replicating the variable or something. The easiest solution is just to make the blueprint that sets it to be the blueprint where it’s located but I can’t do that because I only want that object to spawn after a certain amount of time has passed which will cause problems for my other classes trying to reference the variable before it exists.

My issue hasn’t really been resolved here. I can get a reference to the variable but without being able to externally set it anywhere, getting a reference to it is practically useless.

Hey CBFlood-

Here is a screenshot of the setup that worked for me to call a variable from another function. The bottom section outlined in red is from the blueprint where the variable “CallFromElsewhere” exists. The top section is inside my character blueprint and uses a cast to the other blueprint to get access to the variable. As Arelius mentioned, the variable needs to be public in the function where it exists (the eye next to the name needs to be open). In my case “CallFromElsewhere” has a default value of 0 which shows when I press V. If I click the right mouse button and then press V again it shows the changed value of 9. You should be able to use a similar setup to control your GameOver variable.

Cheers

It won’t let me make the loop or cast to my other class.

You should be able to create the For Each Loop node if you pull off of the “Out Actors” pin from the Get All Actors of Class node. If that works for you then you can do the same thing from the Array Element pin of the loop node to cast to the other blueprint.

If you use a ForEachLoopWithBreak And link from the outgoing of the Set into the Break on the loop, you should be able to early out and avoid looping over all the actors, should there be more than one returned.

But it should be noted, that this approach will only access the variable on a single (first or last, depending on if you break or not) and not every instance.