I’m fairly new to Unity an game development, so this problem is probably mostly based on my lack of understanding of some core concepts.
Let’s say, I’m creating a card game. I have a prefab of a “Card” game object (that has a sprite and script attached, to store some values and allows some card-specific actions). I then have a sort of “Card Controller” that handles managing the whole card collection, e.g. creating it at startup, and putting part of them into a deck to draw from etc.
Thus, I wanted to put a list into my Card Controller, maybe like this:
private List<Card> cards = new List<Card>();
Then I could create Card instances and store them in the list, to retrieve and potentially remove later. However, Unity then tells me that this is not acceptable:
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
Now, I am a bit confused about this as, in my understanding, I’m not actually trying to create a Card instance here, just a collection to store potential instances (which I could create via
I seem to have a fundamental misunderstanding about handling collections of such game objects, but I’m not quite sure where to look to find a better way to approach this. I hope someone could give me some pointers!