Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Instantiate Object of Class for a list

Discussion in 'Scripting' started by MarlouShazu, Apr 2, 2023.

  1. MarlouShazu


    Aug 5, 2020
    I've created a little class to store my Moves, in a turn based combat system upload_2023-4-2_18-16-50.png

    Now i want to add four moves to my player prefab, to test it, but i need to create them somehow?
    I cant seem to create objects with a script that inherits the Move class cuz it wont add to the little list there.
    I thought that i would have to just set the fields by hand in the list on the editor but it wants only a Move type object or something.
    Empty Object with a script won't do it, neither a prefab or simply just a script, so i'm lost here, what do i need to create to add there?
  2. Brathnann


    Aug 12, 2014
    My guess is you don't want Move to inherit from MonoBehaviour. So, either use scriptableObjects or just a regular class and use the SerializedField to make it so you can edit the fields in the editor. Otherwise, you'd have to attach a move script to your gameobject for each move they could do.
    DouglasPotesta likes this.
  3. Olipool


    Feb 8, 2015
    In addition to the above, Unity does not serialize/show properties in the inspector. You have to create backing fields for them like:
    [SerializeField] private string moveName;
    public string MoveName => moveName;
    DouglasPotesta likes this.