Unity Card Game Structure

Use extreme caution with enums in Unity. Unity does NOT store the actual enum such as “Block”.

Instead, Unity stores whatever integer number is associated with “Block”

This means if you have an enum with:

Attack,
Block

and you later add one at the start:

Prepare,
Attack,
Block

Then Block will now be integer 2, and your previously-serialized Block will now magically (and silently) become an Attack.

In my opinion this is a MASSIVE failure in the serialization design that Unity chose but we’re stuck with it. The only solution is to NOT use enums and instead use something like strings, or else make 100% sure you NEVER remove or insert an enum, and only ADD new ones at the end.

You have been warned.

That said, play with whatever structures work best with your design idea, keeping the above restrictions in mind.

1 Like