Need help with dialogue system


this is in my character’s blueprint, it linetraces and hits an npc, if it hits the npc. A dialogue box will appear, and in this box there will be options, like this >

so it’s pretty basic actually. But I tried it, it messed up.
In my game I have a lot different npc’s, and every one of them will have different dialogue stats, they can have same words, but if you tell an npc same thing, it will say “you already said that” or something like that, but other npc’s wont, and they will have different relation levels. That’s what I am trying to do So, Let me explain simply what I did, I gived variables to widget, gived same name variables to npc’s, made npc’s variable set’s the widget variables and gived my character bp to get widget variables to add viewport, but it doesn’t work as I expected because there is a lot casting failings, so guys. How can I do that? can someone explain I really want to do this without any conflicting words of npc’s and any casting errors. I can’t do that bymyself I’m not that smart

What you’re asking is a fairly complicated system, it’s far beyond the scope of a forum answer, I can just give you some directions.

First, you should not duplicate data, never. Pass your NPC Actor to your Dialogue Widget as a reference. When the Dialogue Widget needs to know something about its Owner NPC, just “ask” the Owner NPC.

I replaced your condition check with a type casting check. You can use tags if your project requires it, but if you can talk with all NPCs of this class, there is no need for that tag, just check if the hit actor is from class.

You can see that the Dialogue Widget has a property to reference the Owner NPC and it is set before initializing the widget.

image

If your NPCs always have the same options, you should create a list with all available options.
I created a String Table called DialogOptions with some chat options.

image

In your NPC class you should create a list of available options for that NPC. For example, it could contain an array of Text and you add to the array entries to the String Table

Now your Dialogue Widget has access to this list, and it can show the options.

When an options is selected you could call a function from the Onwer NPC to create a list of selected options or something, and check it.

If you have to save this changes it a whole new topic and system.

wow! thanks for that