Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

scriptable object variable shows <type mismatch> in the inspector instead of a gameobject 976943

Discussion in '2017.3 Beta' started by laurentlavigne, Dec 9, 2017.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    Here is a strange one for you
    https://i.imgur.com/GUoLEc7.gifv
    the code that shows you this behavior is this:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Events;
    5.  
    6. [CreateAssetMenu]
    7. public class GameObjectVariable : ScriptableObject {
    8.     [SerializeField]
    9.     GameObject value;
    10.     public GameObject Value{
    11.         get{ return value;}
    12.         set{
    13.             this.value = value;
    14.             gameEvent.Invoke ();
    15.             Debug.Log (this.value);
    16.         }
    17.     }
    18.     [SerializeField]
    19.     UnityEvent gameEvent;
    20. }
    script that sets the SO's value
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class MakeDummyObject : MonoBehaviour {
    6.     public GameObjectVariable dummyOut;
    7.     public void CreateDummy(){
    8.         if (dummyOut.Value != null)
    9.             DestroyImmediate (dummyOut.Value);
    10.         if (newThing != null) {
    11.             dummyOut.Value = Instantiate (gameObject);
    12.         }
    13.     }
    14. }