Search Unity

ScriptableObject -> is it possible to drop material or texture as in MonoBehaviour?

Discussion in 'Scripting' started by pretender, Aug 20, 2014.

  1. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Am I missing something here? It doesn't allow me to drop reference to material or texture to scriptableobject asset although fields (slots) are properly shown.

    thanks!
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    That should work without issue. Could you show a screenshot and the relevant code for the ScriptableObject?
     
  3. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LevelData : ScriptableObject
    5. {
    6.     public Vector2[] shapeData;
    7.     public int shapeSegments;
    8.     public Vector2[] good;
    9.     public Vector2[] bad;
    10.     public int attemptCount;
    11.  
    12.     public Material splineMaterial;
    13.     public UITexture background;
    14.  
    15.     void Start ()
    16.     {
    17.    
    18.     }
    19. }
    20.  
    here it is, i suspected it should but it doesn't
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    And your material is properly saved in a file, right?
     
  5. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Ok, I don't know what happen but now it works! At least for material. I tried to drag and drop UITexture (NGUI) to slot but it doesn't let me drop texture in that slot.
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You can only use actual files. That means if you create a prefab out of the UITexture, you can drag that prefab into the slot. You can't have anything from a scene in a ScriptableObject because they are independent of an actual scene.
     
  7. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    you were right, I was dragging texture to UITexture slots, and basically that was the problem. Thanks for the help!