Download

I need to know how to set up a basic array with Blueprint Widget Objects

I have requested this before, but nobody here has been able to show me the full node linking that I need to see so I understand how to link this up. This is what I want to do and its a very simple basic thing I’ requesting to know how to do in the engine but for some reason nobody here wants to show me the full set up to this task. One person did try to show me using a text string example but I need to see the example being done instead with PROPER WIDGET BLUEPRINTS so I can understand how its done with the hud widgets system.

Because my dialog is all saved in these little hud designer widget blueprint files. its not saved inside simple print string nodes because the print string node is only for debugging values in the editor.

How its supposed to work…Each time I step into the On overlap trigger, a Different Blueprint widget will pop up on the hud screen, its done with a basic array with blueprint widgets, so I know the components that are needed, what I don’t know how to do is how to LINK UP all the components and references into the array, that’s why I need to see the picture of the whole setup of the array with the Onoverlap trigger with a couple of Blueprint Widgets ref examples so I can see the links, because I don’t know how to set up a basic array with blueprint ref widgets yet with a trigger because I’m not experienced enough yet with programming the blueprints, that’s why I came on here asking for this help…

By getting the engine to pick one widget blueprint reference out at random out of the array slot
each time I step in the trigger. This will enable me to chat to certain NPC’s in my game and get
different dialog back from them to allow them to interact more with my player.

So I need to know how to set the array up with the widget blueprints in Unreal.

Hello. I read your reply to your other thread but before you edited it so I thought everything was somewhat solved, but as I checked it again now, that appear to maybe not be the case. Do you want me to reply to that thread still, if there is something still unresolved?

As for this topic, I need to make sure I understand how you have things set up.
You say “my dialog is all saved in these little hud designer widget blueprint files.”
Do you mean in text variables or something like…

… where textblocks are holding the text you wish to display. And maybe there’s one widget blueprint for each ‘dialogue’?

The way you can store the widget blueprints in arrays depends on what you need to do.
For example, if you only need to add to viewport or remove from parent, then I see no immediate issue. However, if you need some information from the widget, there may be some slight problem. The reason for that is, the array can only hold one class type. (Though one could go around that by using structs but I don’t think that’s relevant in this case).
So if you only want to use the add to viewport function of the widget, then that function is part of the User Widget class (or probably the widget class to be precise but I’m not sure), so we can make an array of type User Widget Class.
But if you need information from the widget blueprint, a variable created in the child class, then if the array is of type User Widget Class, that is not holding that variable, the child is. You could Cast To, as we often do with “get player character, cast to myplayerdudeclass”. But if you have many of these children (sounds like you have thousands?) that you need information from, then casting to the correct one would be a big mess. You would have to create a parent class that holds the information you need and set its information from the children.

So, if you don’t need to get information from the widget blueprints, then just make a variable, type User Widget, then click the array mark.
So, that’s how you can make an array that holds User Widgets. Now, another question is; do you need references or classes. And that brings us to the next part I’m a bit confused about.

“LINK UP all the components and references into the array”.
I’m not sure what you mean by this.
Do you just want to get, say, Widget Blueprint Class #73, create it and add it to viewport? Then you need a class, not a reference.

When creating a variable you can choose between reference and class and some other things. The default is to create a reference.
733f1bc73b8d6cb33221b64634cfb4990da39b91.png

ef8acb44f410b33352c67402785837d47f590d12.png
The reference points to something that is ‘created’. You can see a dropdown list where you can select instances, though there probably are not any in our case.
Class however, holds a class. The blueprints we create are actually classes and we can select the class we need, you can see some of my Widget Blueprints that inherit from the User Widget class.

As for describing exactly how you should go about doing all this… I don’t know.
-I guess the way you create the arrays is to, in the details of the array click the Add Element button (+) for each widget blueprint you wish to have in that array, in their exact order. Or
-In the construction graph or on begin play in the event graph, set the array and use the Make Array node. Then add a pin for each widget blueprint, in exact order.
It may be a lot of work setting the classes of the array(s) but it has to be done somewhere.
Another question is, where do you add these arrays? I can’t answer that. I would do it in either the player character class, some kind of instructor actor placed in the level, or the player controller. Or maybe a struct. Or a data table.
Just consider how you want to handle the array. For instance, if you create it in the droid class and it selects “good day”. Then maybe you don’t want it to say “good day” again, so you delete it from the array. But then, the next droid class might say that because it’s another instance. I guess you could work around that by “updating” all the other relevant classes with instruction “remove index x”. Or create the array(s) in a separate actor, that all relevant classes references when it comes to the dialogue. I don’t know how the arrays would look so it’s difficult to give recommendations, I can only suggest things.

Here was my attempt to try to set it up with the flip flop node… My code is incorrect in a few
places, but this is turning out a little more trickier than I thought… it should be very simple thing
to do to switch between the blueprint segments of code at random.

Here’s the attempt with the Flipflop node with just using 2 blueprint dialog Segments, it didn’t quite work out right. When I step into the trigger with this set up, it plays both segments one after another. When it should only play one or the other depending on which way the Flipflop node goes.

Well maybe I need put in a Boolean value parameter to get the flipflop node to a select 1 or 0 to get it to
switch between the two nodes…

If I can get it working with Flipflop for just two dialogs, great, but for more than 2 blueprint segments, it will
need to be set up with an array. But that I don’t know how to set the array for it.

And Yes my dialog test are stored up in these little heart icon widget blueprint files in these textblocks. I find it I tried to set up the widget dialog up so the trigger only works just once… I know the code at the end is a bit wrong because I used remove all widgets, instead of using remove from parent but I can fix that up later.

what the Dialog Looks like in the Hud within the test map…

And NO I didn’t put ALL my game dialog in these little Heart widget blueprints or I would have thousands of them since my whole windows script code has over 15,000 lines of dialog In it. So I have about 25
dialogs in these widget files as a test to see if its going to work or not.

here’s how I set up the array in Windows script…
cls
set spin=0
set /a spin=%random% %%6+1
if %spin% EQU 1 echo. I’m having a good day today.
if %spin% EQU 2 echo. I’m bored.
if %spin% EQU 3 echo. I’ve got to go now.
if %spin% EQU 3 echo. This is the second line in the array.
if %spin% EQU 4 echo. Hello.
if %spin% EQU 5 echo. Arghh its still going
if %spin% EQU 6 echo. How many slots are there to this thing?

and you can have hundreds of slots in the array…

The screen output of the array will come out like this.

I’m bored

run 2.
Arrghh it’s still going

Run 3
I’ve got to go now

And so you get different random responses coming out of the array every time you run it.

That’s all I want unreal to do, just give me a diferent textblock widget and audio playing
everytime I step into the trigger.

Likewise in Unreal blueprints it shouldn’t be really much different except you have to do it with
the onoverlap trigger and textblock blueprint widgets and audio sound… but That’s what it
supposed to do. so you can swap the text and audio file in the Hud. each time you step into the
trigger, to do that I need to set it up in an array if I use more than just 2 slots to try to switch
things around in the hud.

Since I can’t get it working at the moment with the flip flop node.

So in the windows script, it just selects a random int and based on that, an associated string is displayed. And that’s the array, not an actual array class?
Instead of using a bunch of If statements, a switch: case statement would also have worked. And that you can use in UE:
switchonint.png

Here’s the thing. Doing a sequence of flip flops, sure it could work. But for dozens of items it seems like a big mess. If you wish to change something or troubleshoot, it could be quite the ordeal.
Also, having text in textblock widgets won’t allow you to localize easily if that is something you plan to do. Then the dialogue needs to be in text variables.
Either way, I suggest trying to find a more structured way of doing things.

This tutorial from Epic shows how to create a simple dialogue system, though it does not seem that amazing.
Another project which seems really cool is Dialogue System - Work in Progress - Unreal Engine Forums
where you can download the project and dive into their blueprints.

The most crucial thing for you to consider, I think, is the use of the widgets. Do you really need to have each dialogue in a different widget, hardcoded with textblocks? You could have just one widget that displays the dialogue, depending on a text variable.

Something that might be useful is the use of data tables. Data tables needs one type of struct class which determines what information the data table can hold.
I think you said you have spoken dialogue, so associating each sentence with a sound file would be easy.
e7c79332b36b03c89b20308c5212f594da674b98.png
This data table has the following struct

Using Data tables has their own challenges and two things to know is that you can not modify a data table (at least not using blueprint) during the game, and that the way you get to the data in the colums is by inputing the exact Row Name.
9738f4642684ccb0840ef6875fe4c3ab666800e4.png

In the example above, using random int we can do something like…


So instead of using the whole flip flop thing, or a switch on int, this is pretty much all we need to select the desired dialogue.

And more, the struct can hold widget classes in case you still want to go with that instead of a text variable.

The behaviour tree system sounds interesting because that system is similar to the array I use In my Windows Script, I used a lot of IF statements in my code because I was dealing with other FLAGS and variables also in the game. Not just dealing with just party member dialog flags.

I wasn’t concerned about whether the NPC brings up the same line again, because
the way I set up the array it simply picks a slot out at random. And display one line of
text and plays the audio to it. And its when you replay the game and go back to that same scene
to replay it, that you will get different text and audio output from the array.
This Data table also sounds interesting… so is this a text file that you need to have all your rows
of dialog in ?

Now BACK TO UNREAL, if I use a single widget example instead of using hard coded textblocks for my dialog, then we still need the system to change the party member pics around depending on who is doing the talking.

I find this a lot more tricky than i thought in trying to set the same system up in unreal, but
very easy to set all up in windows script

I see. So were you trying to recreate that %spin% EQU with the flipflop nodes?
72063f7fc9e34f1d5d36497357d12aaa493f7bcd.png
The if query you are doing in windows script is the equivalent of the sequence on the left side. That can be simplified with the switch statement on the right side.

As for the behavior tree dialog I can’t help you for I have not begun to learn that yet.

As for the data table - you can import data from a CSV file.

But you don’t have to, you can add rows and data without leaving the engine. You can create a data table by rightclicking the content browser - miscellaneous - Data table. In the window that pops up, you select the struct you wish to use in the table.

As for showing the correct picture, if we in the widget create a texture 2d variable, we can bind the picture to that variable. We can then set that variable with the correct person.

In the first example, just like how we pass the text we want to show up, we also pass in the persons picture (in this case as texture 2D) directly.
In the second example, an enum value is sent, and depending on the enum value, we set the Bound Picture variable with a persons.
In both cases, you need to know who is talking, and that should be determined in the blueprint calling the widget blueprint. The second example would be the most practical if many different blueprint classes are calling it.
How you determine who is talking depends on what system you decide to go with.