Best way to store and create variations of NPCs

Godot Version



I have an NPC scene that I make several instances of in my game. I would like to add some variation by creating them with different parameters such as the color (that I implemented through a shader). I need to store these parameter values somewhere and retrieve them while spawning the NPCs. I can think of two ways to do it:

  1. I can store all the properties as a dictionary somewhere (currently a JSON file that I read with preload()) and use a function that sets the relevant properties of the NPC to those in the dictionary’s relevant entry. Godot seems to not like this option as it can’t even properly show me the JSON file on the editor, so I feel like this is not the proper way to do it.
  2. Use a function in the NPC scene’s script that matches the type of NPC to the one I want, and also sets the properties. This looks like too much data clutter for a function.

Is there a proper way of doing this that I am missing? I don’t want to use subclasses because I won’t add any methods, just fine tune a few numeric parameters.

(I would also love to be able to set the type as a parameter when I instantiate, and put the relevant code under the ready() function, but I assume that’s not possible.)

Thank you!

I think it will be better if you define a data {} variable in Global and store the properties of the ncp, then while spawning the ncp, you can use the data

You could use resource to create variations or create new inherited scenes of your character scene and change the required properties for each. Writing on my phone, so I kept this short.