Scriptable Objects with Characters

Hi, sorry if this is the wrong place to post this.

I’ve got experience with game design, but only a little with coding, so this might be a pretty basic misunderstanding of how the editor works with scripts. I’m working on a party-based roguelite, and needed a way to have a team of characters, think Pokemon or Darkest Dungeon, with a mechanic where the player can recruit or dismiss characters. I’ve been using prefabs for the basic units, and then adding the specific stats / sprites / etc with scriptable objects, and that’s been working so far, but I can’t figure out a way to generate new scriptable objects from within the game that would act as potential recruits.

Should I not be using prefab base units at all, and instead just put all of a character’s information in one scriptable? Either way, I can’t figure out if there’s a way that I could create new temporary scriptables during runtime. I could just have a set number of blank ones created in the editor, and just change their variables at runtime, but this seems like a workaround for something that probably has a more efficient solution, and this would lead to issues with setting a roster size (the difficulty of the game scales with the number of characters being used, so I want to give the player the option to choose the size of their encounters) and with mechanics I was planning to add later, like tombstones or dismissed characters returning in later playthroughs.

Basically, I’m asking how to create scriptable objects at runtime, and whether this is something that I should be doing in the first place. Any help is appreciated! :slight_smile:

Per the docs, there is CreateInstance<T> to make a new instance of a particular SO type. Additionally, as they are UnityEngine.Object’s you can Instantiate() them to make copies of existing instances.

However if you are making instances of SO’s during run time, you should consider if it brings any advantages over just using plain classes. The only reason I can think of is if you’re using JSONUtility to serialise your temp SO’s, but that brings it’s own issues.

Personally if you need to create this kind of run time data then I’d stick to plain C# classes. You can of course have SO’s that wrap around these for pre-made characters, but using plain classes will be a lot more straight-forward with regards to generating stuff on the fly.

Also, make sure you have a plan to save this data ahead of time.