Search Unity

Possible Bug

Discussion in 'Scripting' started by MertailAtHome, Jun 20, 2019.

  1. MertailAtHome

    MertailAtHome

    Joined:
    May 22, 2015
    Posts:
    12
    Using Unity 2019.4

    Yesterday I tried the following:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    namespace Puzzle.GreatAlembic
    {
    public interface _OutputMultiplier : MonoBehaviour
    {
    void Multiplier(float factor);
    }
    }


    and then set up another class with a public array as follows:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    namespace Puzzle.GreatAlembic
    {
    public _OutputMultiplier[] item;
    }


    The inspector didn't show the array at all. However, when I changed from an interface to an abstract class:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    namespace Puzzle.GreatAlembic
    {
    public abstract class _OutputMultiplier : MonoBehaviour
    {
    public abstract void Multiplier(float factor);
    }
    }


    it worked as expected
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    My understanding is Unity does not expose fields in the inspector which are of an interface type. Also, use Code tags when posting code into the forum, and Unity 2019.4 won't be released for another 10+ months.
     
    lordofduct likes this.
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    I don't even know how your first one even compiled... you can't have an interface inherit from MonoBehaviour.

    And yeah, Joe-Censored hit it on the head. Unity does not support serializing interfaces.
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    error CS0527: Type 'MonoBehaviour' in interface list is not an interface
     
  5. MertailAtHome

    MertailAtHome

    Joined:
    May 22, 2015
    Posts:
    12
    The easiest solution was to simply convert it to an abstract class.