How to pre-generate and "save" characters/items

Hey all. My characters and items are completely random gen. With lots of different stats, descriptions, visuals and effects, my characters are getting quite complex as well.

Understandably generating everything on the fly makes the game have it’s hiccups. All the code that random gens the npc and items, building etc… is random and done in the constriction script.

My question; is there a way to generate a library of npc, items, etc… On begin play, then save them and when the game needs to generate a new item instead pulls from the list of saved ones. Then when the list gets low enough repopulates it?

Any help appreciated, thanc.

Sure, just spawn them early, keep them in an array or a map, hidden. You will pay for this with a higher memory footprint, of course. You cane use Game Mode / Game Instance for this since they are easily accessible from anywhere.

What you’ve described is very similar to pooling. If you want to have 100000 bullets flying around, spawning them (very costly) will cause performance issues. Instead, they are spawned before combat and kept in a pool - if you need one, you take it from the array (it’s just a pointer so the cost is minimal) and handle it the way bullets handle. Rather than destroying them, you put them back in the pool. Pretty much every games does this.

I simplified it a bit but that’s the gist.

edit: alternatively, pre-generate data, save structs to a Game Object. Spawn blank object without running the costly generator in the Construction Script and grant it data loaded from the slot. This may be a better solution if it’s the random generator that is slowing everything down.