Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Can't drag scriptable object into serializefield value in inspector

Discussion in 'Editor & General Support' started by Stixxy, Jul 19, 2022.

  1. Stixxy

    Stixxy

    Joined:
    Feb 26, 2019
    Posts:
    37
    As the title says, I've created a scriptable object, but when I try to drag it into a value in the inspector, it doesn't work. I tried selecting it from the asset menu aswell, and it shows up, but when I click it it still doesn't show up in the serialized value.

    Here's the code for the scriptable object:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [System.Serializable]
    4. [CreateAssetMenu(fileName = "Lighting Preset", menuName = "Scriptables/Lighting Preset", order = 1)]
    5. public class LightingPreset : ScriptableObject
    6. {
    7.     public Gradient AmbientColor;
    8.     public Gradient DirectionalColor;
    9.     public Gradient fogColor;
    10. }
    And here's the value I'm trying to put it in:

    Code (CSharp):
    1.  
    2.     [SerializeField]
    3.     private LightingPreset preset;
    I have no idea why it doesn't go in. Thanks to anyone who has any advice about this situation.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,102
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,228
    Also worth noting that System.Serializable is unnecessary on Unity objects.
     
  4. Stixxy

    Stixxy

    Joined:
    Feb 26, 2019
    Posts:
    37
    Thanks for the replies guys! I had an error in my code, and when I fixed it the problem went away. I really appreciate your help :)
     
  5. gamedevjake

    gamedevjake

    Joined:
    Aug 16, 2022
    Posts:
    29
    Had a similar issue today but no errors. The solution was to change the folder of the Scriptable Object files to some "TempFolder" then to move them back to the original folder. Something got out of sync but was not Cleanable/Cache-clearable when someone reorganized some files and pushed the changes to Git.