Dialogue System

I tried to add a dialogue system in my game and it works pretty well but there is a problem. Every time I change the line the character is supposed to say it just spawns a new widget with just that line.
The code:


I put a ‘Do once’ node on the things I want to happen only at the beginning of the dialogue but it does it every time regardless of the ‘Do once’ node. If you need any further info just ask me. Thanks in advance.

DoOnce will work as you want in the event graph only. This node resets every time you call the function.

Any ideas on how to make it to ‘do once’ the thing I want?

Hey there @DeiankataTV! So your system is actually designed in a way to create a new widget every time. If you wanted to instead have a widget that changes text you would spawn one at the beginning of your interaction, and then just set the text on it every time you want to change lines. As of now your Add Dialogue Widget area just makes a new one. You could take that, fire that once and first, then take that reference, and pass the lines to it. Then when done, you unparent the old widget and it’ll be garbage collected.

DoOnce is a special Blueprint node. It cannot be used in Functions as Functions tend to have a more ‘normal’ programming style.

You can easily mimick the DoOnce node, the same way all C++ developers do:

  1. create a class boolean variable called ‘WidgetSpawned’.
  2. Replace your DoOnce node with a branch that checks if WidgetSpawned is false, and if it is, set it to true and proceed with creating the widget.
  3. Repeat with every DoOnce node.