Best way to save multiple NPC positions?

I’ve been trying to figure out what the best way to save multiple NPC positions when transitioning between levels.I have it working for the player using a persistant game instance, but I’m not sure what the most efficient way is to do that for such a large amount of NPC’s.

How many NPCs are we talking about?

I wouldn’t know why having an array of like 1000 vectors would have that much of a performance hit. Have to try it out though, but my expectation is that it doesn’t really matter. Just keep it somewhere persistent like in the game instance.

Might as well be an array of structs or something, so you can do some sort of mapping?

So you’re saying to make a vector array, then when moving in between levels to save and set that variable? How would each actor know which vector is their own?

I have to admit I am not that experienced with map transitioning as I didn’t use is so far.

I imagine AI gets destroyed and respawned when you transition out and back into a level?

Also, are your NPCs special (like named NPCs) or just mobs?

If they are just mobs, you could make a struct with

  • Class
  • location
  • current health
  • etc

and save them in an array. Once you come back, you spawn them and update all their values.

If they are unique NPCs, maybe you’d do good with some sort of ID variable? Although, if they really are, the class would be enough.

I really don’t know if there is anything like this prebuilt, but this would be how I’d try to solve this.

Is it multiplayer?

They’re specialized, unique units that contain an army of units within them. (Think Mount and Blade overworld style enemies)
I’ll attempt to make a vector array with a specific ID designation like you recommended. That seems like the most logical step right now.