Set text values with public variables

I’m attempting to make a map players can move around, with pins they can click on to show the information of npcs that live at that location. I’m fairly new to blueprint scripting, so there may be a better approach. This is just what I have pieced together with various tutorials.

I have created a blueprint with several public variables that I use to set the values of a struct table. That table is used to set the text value of a widget by casting to this blueprint to fetch the value of the variables.

The idea is that I would be able to have multiples of these pins on the in the viewport and set the text of each individual, while reusing the same blueprint, so that I don’t have to create a new blueprint for each npc. To some extent, this works, and I can set the text through the editor/outliner, but the issue is that it sets the same text for every instance of this blueprint. Generally, the editor uses the text from whatever instance I set most recently to populate all of them.

344652-help2.png

344653-help3.png

Is there a better way to approach this, or something I’m missing so that each instance of the blueprint uses it’s own information?

  • functions bound to text blocks (2nd pic) execute every frame, if you mouse over the Get All node, it will tell you not to use it every frame as it’s a slow operation
  • Get All does not guarantee element order, you actually do not know which element you’re getting
  • even if you knew which index is which actor, you’re Getting element 0, getting text of that actor and setting it to all actors text. All actors end up with text from actor 0 (and we don’t even know which is 0 - this will seem random)

Just to clarify, it’s like this right:

  • actor
  • widget component

Each actor has a bunch of variables that you set and you need each actor’s widget to show them. Could you confirm?

Here’s something that I tried to fit into the existing bits you’ve learnt.

  • inside the widget with the text blocks, create the same struct variable you have in the pin actor - so you can poll that struct’s values and feed them directly into the fields:

344661-struct.png

  • in the actor with the widget component:


Do note, you do not really need to make several text variables and assemble them into a struct, instead you can flag the struct variable itself as Instance Editable and then:

Thank you! This worked for me! The only issue I ran into was your comment about being able to make the struct instance editable. With public variables fed into the struct, I could set the text of each instance, but if I just tried to set it through the public struct, it didn’t work. The text showed as blank.

Looks like that was the case with the variables overriding. I got rid of them and it’s working just fine now!

Just a follow up, this may be a more involved, but is there any way to bind the text in the widget to a text array element, rather than a single text variable? I don’t see the array come up in the binding drop down. If not, that’s fine, I was just hoping it was an option for organization’s sake. Thanks again for the help, I really appreciate it.

344675-binding.png

The text showed as blank.

Hard to tell what’s up without seeing more but perhaps the variables you previously set up override the data in the struct? Were you to go with the Instance Editable struct:

That is currently not possible in BPs. One easy workaround is this:

344694-screenshot-6.png

You’d need to punch in index manually for every field but this can be automated further. Irrelevant if you have 5 fields, and pretty much a must if you have 500 fields…


Alternatively, you could expose Text Blocks as variables:

344696-screenshot-7.png

  • inside the widget:

  • and instead of setting the struct value, call a custom event which will do both - set the struct value and push text into fields

Or perhaps the struct inside the widget is not even needed, the Custom Event may be enough to set everything up. Although having a struct may help with other things.


This is especially useful when you know the data will not change often or not update at all. Binding something to a widget field executes every frame whereas the above would execute once. If you have 10 Pin actors, it does not matter. If you have 1000 pins, it does.

Oh, this makes sense! I should have caught that now that I know how to set the struct values from the blueprint. Thank you!