Hello everyone, I am trying to assign variables to my NPCs at random and have them display when I click on the NPC which pulls up the widget showing their information (will figure out how to save this information at a later point)
So I created this function in the NPC BP to generate the variables at random from a data table.
But nothing is show in the text boxes, I do get a accessed none from the UI (my most common error). So how can I get this to work? I tried casting to the UI from the NPC BP, I tried storing the NPC BP as a variable in the UI widget. but neither work
The first function is incorrect, sequence pins 1&2 never run as you return early from the pin 0. Only family name would be generated.
The dreaded Accessed None comes from the ref in the 2nd pic, I presume? The widget does not know which Farmer you mean. Creating a variable and not telling it which actor you mean will not work. What if there are 3 farmers?
There’s a more straightforward way of doing it. Hear me out.
Is the widget a widget component? If so, the whole thing could be done inside the the Farmer BP and boiled down to:
Run it on Begin Play. It’s the farmer’s widget, so they tell the widget what to display. Having widgets pull data out of somewhere else feels like pulling teeth. Necessary at times but to be avoided.
Another, much grander question, is to whether the farmer needs a generator function in the first place? If there are 1000 NPCs like this, each must know this function. Normally one would have a function like this in a dedicated manager BP that does the generation, or even in a singleton framework class - like the Game Mode, for example.
A farmer would ask another blueprint to generate them some vital data. The farmer’s job is to farm, not to generate names :]
It’s usually more convenient to tell the widget to do something, rather than have the widget look up things. The widget’s job is to display stuff, not to look for stuff to show. The widget can format the data you give it.
current code for generating the code is a function created inside the Farmers BP.
It’s probably fine. It would work, but in the long run it pays off to have a dedicated actor to do the generation. Normally you supplement your actors by all kinds of managers that do specific things.
I do have a game mode set up, so I can set that function up in the game mode and ask the farmer to get that function?
Yup. You could move the function there (you could probably copy and paste it) and:
If I was to set the function up as a dedicated actor, what kind of blueprint actor? would this been more efficient than putting it into the game mode BP?
So I tweaked the function, place it inside its own actor BP and tweaked it so it doesnt finish so early, though I release I could be pass it to some thing that is false, is there a node I can pass it to to help it finish?