I am trying to load a variable from the level blueprint to display on the HUD.
Every single tutorial that I can find that grabs variables from other blueprints (end goal) uses “get player character” node. The thing is, I don’t have a player character, I am building a 2D mobile game that doesn’t rely on any kind of player avatar. I put some variables (currency, XP) in my Tile Map, but I cannot seem to find a “get” node that pulls the appropriate class to actually access them.
Basically what I know is that the blueprint that contains the variables I want (a Tile Map) claims it’s parent class is “Paper2D.PaperTileMapActor”. When I hunt down “get Paper Tile Map Actor” it only offers “render component”, which causes a critical error in the compiler.
I am so thoroughly confused by now that I don’t know what questions would be helpful to me! Someone please explain why one “get” node seems to work differently than every other “get” node, or maybe just describe ways to work with it that don’t involve an actual player character.
I am currently updating to 4.12, if that makes a difference. Seems to have finished downloading, but installation is taking a very long time.
You’re very close to having what you want. Whenever you use Cast or Get, you’re getting a reference(Cast)/value(Get) to that asset/variable in that one instance, but you’re not storing that reference.
With the picture you showed above, you’ve promoted the Restaurant BP reference to a variable, which is good. This means that there is now a variable in your Widget that is storing the reference so that you can use that elsewhere.
When you do a “Get IGC” from the As Restaurant BP pin, you’re getting that variable’s value at that moment in that class to be used at that moment as well. Seeing as the end of this isn’t connected to anything that is ultimately connected to an executable node, it’s doing nothing at all.
If you wish to bind the action of a certain part of your widget to the value of the IGC you’re getting, you’ll need to promote it to a variable as well. Right-click the “IGC” pin and select “Promote to Variable”. Once the variable is created and is stored in your widget permanently, you’ll be able to use it as a binding.
Keep in mind however, while your Restaurant BPRef is a reference to an asset and will update its values as that asset updates, this new variable that is being created from IGC is only getting the value of IGC at this particular moment. If IGC is ever updated or changed again and you wish to reflect this in your HUD, you’ll need another event to update this variable as it won’t be updating dynamically otherwise.
Got it to work in 4.12! With this, I should be able to refer to any variable in any blueprint! Start from the left and drag from each pin, then type the name of each block, replacing PaperTileMapActor class with the class of your blueprint, and “Restaurant_BP” with the name of your Blueprint. To call your variable, drag the reference variable from the bar at the left of the graph, then type in “get YourVariableName”. Use the reference variable as the target and you’re golden.
This is what I have so far… it seems to work. I haven’t put in a function to update the display yet… or even change the values ingame. Would it be more efficient to update each displayed variable or tell the game to redraw the HUD? Would redrawing the HUD cause a noticeable flicker in display?
What are the costs if I don’t set the variable to a reference like you said? This game will have a ridiculous amount of content, and I want to be able to download the whole thing to my phone, so I’m concerned about optimizing as much as I can.
For your method of getting the Restaurant BP reference, simply having a variable that stores a reference to it would be better. The Get All Actors of Class node can be very unperformant, especially when there are a lot of actors to search through.
I can’t quite tell in the 2nd picture you provided, but is that a function you created or a binding? If you haven’t tried it and are strictly against creating a variable for this value, you could use the “Create Binding” button to create a function that will allow you to apply the value directly.
As far as updating the value or redrawing the HUD, updating the value would be the most simple and best as far as performance goes. Once the binding is set up, all it takes is literally changing the value and it’ll update. There’s no reason to redraw the whole HUD every time a value changes.
I would suggest watching this tutorial if you have the time to get an idea of some good practices. https://docs.unrealengine.com/latest/INT/Videos/PLZlv_N0_O1gYqSlbGQVKsRg6fpxWndZqZ/abmzWUWxy1U/index.html