I finally took the leap into using scriptableobjects to store data and it is looking a lot more interesting than I ever thought a data container could be!
So I am wondering if it is practical to use scriptableobjects to solve for instantiating the right player model. I have the following situation in my project:
The player starts as a small creature and as they gain levels, they get bigger.
When the PC ages, it needs to use a different model in the next ‘life stage’.
Each model has different settings in its controller that impacts on movement speed, swimming, etc. as well as a different-sized collider.
I have tried using a root gameobject to house the models, but it causes me issues with cameras, animations and finding the PC in my other scripts.
I have tried using just instantiation as well, but some of the add-ons I use want a specific model and not a tag which frustrates the situation.
So I am wondering if I could not create a scriptableobject asset for each ‘life stage’ that has the prefab reference, model material, the stats, etc in the .asset file and then reference the asset from the root PC gameobject or something? Would that work? Could I set the values in the .asset file to be updated (e.g. XP and ability points) instead of housing it in PlayerPrefs? How would I then reference the SO data fields so the right info is used ingame? Help would be much appreciated.
The ScriptableObject solution is a good one, and it should work just fine. I’ve got some questions, though:
Not quite sure what you mean here? If you’re going to replace the model, you’ll have to instantiate the next version somehow. You’ve got addons that you need to send a reference to the model?
Not sure I get what you mean here either - are you talking about saving and loading? In that case, no, you can’t store player data to assets. Assets can’t be changed after you build the game.
Some of the addons I use in my project wants a reference to the player gameobject, so I have to drop a prefab into the relevant fields in the inspector instead of being able to use something like a player tag instead. This is why I have tried to use an empty root object to house all the different player model prefabs, but then have issues with animators and controllers since they are not quite the same on the different models.
So what I would like to do is have a scriptable object for each possible player prefab which then holds the gameobject and other static info. Depending on which player model would be used, maybe I could reference it? Not sure if this would work or not or how I would do that.
Ah, thank you for that. Will have to look for something else to house stats, XP, etc.