How to efficiently update a single entry in a struct?

I have a few NPCs in my game, and each one has their own data table containing all dialog lines associated to them. I store which one is the current line in a variable inside the game instance bp, which is saved by the player into a savegame, and retrieved from it on loading game.

The problem is that when talking to an npc, in order to save the current dialog line, i have to update the variable associated to them, while keeping the other npcs’ lines the latest they were at.

This becomes a hurdle when I want to add another npc, cause I have to manually connect a lot of nodes, like this:

How can I do this more efficiently so each new npc added has its dialog line automatically routed?

Drum roll…

:slight_smile:

2 Likes

hmmm, something like this, then?

It really simplified all that spaghetti, which helps a lot, but it still doesn’t really “automate” character creation, every time I add a new character, i gotta go there and ad a new “set members” node and connect.

this wouldn’t be much of a problem, if this was the only function where I needed to do that, but there are a few functions getting or setting data from each character, such as this one or those ones, for example: (and a few more)

and I’d need to manually update each one of them whenever I added a new character. So how could I possibly get rid of all this manual work?

The only thing that comes to my head is by using arrays instead of structures, so I would just add a new character to an array, and use for each loops, but I don’t even know how to begin that transition.

I haven’t look at this is great detail right now ( no time right now ), but it sounds like what you need is blueprint inheritance.

If you make a character that has one set of these values, then ever other character can inherit from it, and override the values in a way specifc for that character.

Does that make sense?

Don’t leap into that headlong, I could be wrong, will look when I have a bit more time.

I’m also wondering why it can’t be one character with different initial values for the structure…

saving variables from multiple actors should be handled through an actor component which contains a custom event that is fired when the Save Game event happens from the player, grabbing each variables like that… well that’s hardcore!

if you dont want to inject all variables into one slot consider making save slots for each character class, so when the event is fired from the component it doesn’t have to communicate back to the player save slot.

You still have spaghetti here… :slight_smile:

I think the OP is looking for something that doesn’t expand as the options do.

Ok, I looked at it.

What I don’t get is why you have a struct for each person. Why is there not just one generic character which, when instanced, can get their ID, name, current line etc. Surely this is the same for everyone?

Sorry if I’m totally missing something here, very possible.

So I’m saying just totally generalize the NPC, so there is only one, and it knows what data to use based on just one thing ( like name or ID ).

I just had a quick go at this, but data tables always seem like a lot of hard work to me :smiley:

All you have is a row name, really? I would be tempted to read it into something more useful, at startup

You can just read the whole table into an array of structures, and then later just search it for your ID and sentence number. Much easier.

Then I can just get my line number from the save game ( or whatever ), and find it in the array.

I hope that makes some sense… :melting_face:

1 Like

yea if you’re gonna keep adding more options then just do as Clock said, one struct var in the actor is enough it doesn’t need to be nested.
a map based on the SKM or Name var is enough to handle grabbing the correct settings

I dont get it with this spaghetti thing, no one is gonna look at it except the devs so if its gonna happen one time (common function library / macros) and can make out whats happening then big deal its all behind the scenes when its called its just collapsed into one node

1 Like

The point is, you have to keep adding code, when you add NPCs. That can’t be right…

1 Like

I must have one dialog data table for each npc, regardless if all npcs are just the same actor with a different skin, because the dialog data table has hundreds of rows.

And the columns in this table are: Row Name, ID#, Next line #, Should end dialog, scene#, speaker, line, choiceA, Choice B, ChoiceC, Choice D, requirement C, requirement D, facial expression, body gesture, outfit, should save, execute event.

might even add more columns in the future.

I literraly edit a .csv file in excel with all the dialog, and then import / reimport it into unreal as a data table for each character. that’s the best way I could come up with

Sure I could add a variable to each npc saying which data table it should use, but I still need to save into a savegame which line each npc has stopped at, and if their dialog is active or not. each npc also has to have their location, current outfit pieces, (and probably more stuff in the future).

I am not sure why I have a struct for each person. It’s the same struct layout, but each npc has their own to save all their personal info. this is probably what I want to make better, but don’t know how exactly. I came up with all this dialog system myself, along with some help I asked here a while ago, but it got kinda complex and bloated, so I’m really trying to make it more efficient somehow. I literally spent a whole day when I went back to this code to add a couple more npcs after a few months doing something else, so I really need to automate it :sweat_smile:

1 Like

Yes, I think it is possible to have one NPC codebase, and work from that. One structure etc.