Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question How to keep data of a custom editor that deal with scriptable object when saved as prefabs

Discussion in 'Editor & General Support' started by JMAff, Aug 2, 2020.

  1. JMAff

    JMAff

    Joined:
    Jul 6, 2020
    Posts:
    5
    Last edited: Aug 3, 2020
  2. JMAff

    JMAff

    Joined:
    Jul 6, 2020
    Posts:
    5
    Here's an image to clarify. I'm trying to keep the text and audio reaction inside a prefab.



    Unfortunately, it doesn't like that and the data disappears when you try to add reactions inside the prefab.

     
    Last edited: Aug 3, 2020
  3. JMAff

    JMAff

    Joined:
    Jul 6, 2020
    Posts:
    5
    I tried using: if (GUI.changed) { EditorUtility.SetDirty(interactable); } and Undo.RecordObject(interactable, this.serializedObject.ToString()); inside OnInspectorGUI() but to no avail.
    Another solution would be to write a script to remap this data at run time, but that's not ideal.
     
    Last edited: Aug 3, 2020
  4. JMAff

    JMAff

    Joined:
    Jul 6, 2020
    Posts:
    5
    Looks like I spoke too fast so I tried the other alternative. Using presets to load the saved data at runtime, but it doesn't apply to the object.

    Code (CSharp):
    1.  item = Instantiate(itemToAdd.itemPrefab);
    2.                     if(itemToAdd.preset.CanBeAppliedTo(item))
    3.                     {
    4.                         itemToAdd.preset.ApplyTo(item);
    5.                         Debug.Log("Preset applied!");
    6.                     }
    7.                     else
    8.                     {
    9.                         Debug.Log("Preset not applied...");
    10.                     }
    Does anyone got some suggestions, some pointers?
     
  5. JMAff

    JMAff

    Joined:
    Jul 6, 2020
    Posts:
    5
    Another alternative instead of instantiating prefabs is to configure all the objects you plan on using in advance. Turn them on or off depending on your need. I was wondering maybe the fact that I'm dealing with scriptable objects makes it that it cannot be saved as prefabs?