ScriptableObject and Monobehaviour

Hi, i have a class Warrior that inherits from a class Character, these warriors have to be saved on a Dictionary.

Dictionary<string,Character> characters = new Dictionary<string, Character>();

To save them i’m using:

private void createWarrior(string name){

	warrior = gameObject.AddComponent<Warrior>();
	warrior.setWarriorAttributes(name,1000,1,3);

	characters.Add(name,warrior);
}

But with that each time a create a new Warrior a new Component is Add to a game object, and at this point i only want to save them in the dictionary. But i can’t use ScriptableObject because later i have to instantiate prefabs with the script Warrior and he has to be inherits from MonoBehaviour so i can do it.

With what i replace AddComponent ? I tried use new:

Warrior = new Warrior()

It works, but unity gives me a warning, and i read that’s not recommend.

Sorry for my english, google translate.

You cannot create a MonoBehaviour unless it is attached to a GameObject.

You could make a new class WarriorAttributes : ScriptableObject. When you are ready to instantiate a Warrior, you can set its state from WarriorAttributes. A little bit like the Memento pattern.

Alternatively, you could instantiate new GameObjects, attach the Warrior MonoBehaviour, and make it inactive until you wish to use them with gameObject.SetActive(false)