Search Unity

Calling a Texture from a scriptable object that is in a scriptable object. [Resolved]

Discussion in 'Scripting' started by GlitchInTheMatrix, Sep 19, 2018.

  1. GlitchInTheMatrix

    GlitchInTheMatrix

    Joined:
    Apr 12, 2010
    Posts:
    285
    Hi Guys, Im working in a Customized Scriptable Object base system.

    On this system, from a Script I call a texture that is situated in a scriptable object that is situated in another scriptable object.

    [Game Object, contain the script that make the call]
    .....L [Scriptable Object A]
    ..........L [Scriptable Object B] < Located in Scriptable Object A -> Portrait001
    ...............L [Texture] < Located in Scriptable Object B -> PortraitArt

    So I tried something like this:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SelectScreenMaster : MonoBehaviour {
    6.  
    7.     public CreateSelectScreen selectscreenchars; //Contein the Scriptable Object A
    8.     public GameObject[] Portrait; //Mesh where will assign the texture
    9.  
    10.     void Start () {
    11.          Portrait[1].GetComponent<Renderer>().material.mainTexture = selectscreenchars.Portrait001.PortraitArt;
    12.     }
    13. }
    Got an error in this line:
    Code (csharp):
    1. Portrait[1].GetComponent<Renderer>().material.mainTexture = selectscreenchars.Portrait001.PortraitArt;
    Error:
    (13,101): error CS1061: Type UnityEngine.ScriptableObject' does not contain a definition forPortraitArt' and no extension method PortraitArt' of typeUnityEngine.ScriptableObject' could be found. Are you missing an assembly reference?


    Anyone have experience working with Scriptable Objects? Thanks
     
  2. chatrat12

    chatrat12

    Joined:
    Jan 21, 2015
    Posts:
    122
    According to your error message, 'Portrait001' is of type
    ScriptableObject
    .
    ScriptableObject
    in fact does not contain a definition for 'PortraitArt' :D Can I see your
    CreateSelectScreen.cs
    ?
     
  3. GlitchInTheMatrix

    GlitchInTheMatrix

    Joined:
    Apr 12, 2010
    Posts:
    285
    Thanks chatrat12

    here is:
    [Scriptable Object A]
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. [CreateAssetMenu(fileName = "New Select Screen", menuName = "Select Screen")]
    7. public class CreateSelectScreen : ScriptableObject {
    8.  
    9.     public ScriptableObject Portrait001;
    10.     public ScriptableObject Portrait002;
    11.     public ScriptableObject Portrait003;
    12.     public ScriptableObject Portrait004;
    13.     public ScriptableObject Portrait005;
    14.     public ScriptableObject Portrait006;
    15.     public ScriptableObject Portrait007;
    16.  
    17. }
    [Scriptable Object B]
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [CreateAssetMenu(fileName = "New Character", menuName = "Character")]
    6. public class CreateCharacter : ScriptableObject {
    7.  
    8.     public string CharID = "ch_";
    9.     public string CharName = "";
    10.  
    11.     public GameObject Char;
    12.  
    13.     public Sprite BioArt = null;
    14.     public string BioText = "";
    15.  
    16.     public Texture2D PortraitArt = null;         // <-------------------- Call This Texture
    17.     public Sprite VSArt = null;
    18.  
    19.     //------ Final.
    20.     public ScriptableObject CommonMoves = null;
    21.  
    22.     //------ Final.
    23.     public Sprite Final1Art = null;
    24.     public string Final1Text = "";
    25.  
    26.     public Sprite Final2Art = null;
    27.     public string Final2Text = "";
    28. }
     
  4. chatrat12

    chatrat12

    Joined:
    Jan 21, 2015
    Posts:
    122
    You need to change
    public ScriptableObject Portrait001
    to
    public Portait Portrait001
    where 'Potrait' is whatever the name of the scriptable object's class is.
     
  5. GlitchInTheMatrix

    GlitchInTheMatrix

    Joined:
    Apr 12, 2010
    Posts:
    285
    Yeah, that was the problem. Thanks!