Search Unity

Resolved Issue displaying properties of a ScriptableObject within a MonoBehaviour Custom Inspector

Discussion in 'Scripting' started by user142, Feb 12, 2024.

  1. user142

    user142

    Joined:
    Jan 4, 2022
    Posts:
    5
    Hey everyone,

    I'm currently facing a challenge while working on a custom inspector in Unity using UIToolKit. I have a MonoBehaviour called WorldGenerator, and within it, there's a property named GenerationData, which is a ScriptableObject. My goal is to create a custom inspector using UIToolkit that displays both the properties of WorldGenerator and the properties within GenerationData.

    So far, I've managed to display the properties of WorldGenerator in the custom inspector, but I'm struggling to figure out how to access and display the properties of GenerationData within the same inspector.

    I've searched through the documentation and various forums, but I couldn't find a solution that addresses this specific scenario.

    This is the code:
    upload_2024-2-12_19-5-43.png

    The result:
    upload_2024-2-12_19-7-15.png

    Thank you in advance!
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,923
  3. user142

    user142

    Joined:
    Jan 4, 2022
    Posts:
    5
    That's what I'm trying to use above, as you can see in the "InspectorElement.FillDefaultInspector" but it doesn't work, I'm not quite grasping the 'bind' part of the InspectorElement :(
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,923
    Instance one with
    new
    , bound to the scriptable object, then add it to the visual element tree.
     
    user142 likes this.
  5. user142

    user142

    Joined:
    Jan 4, 2022
    Posts:
    5
    It worked! thank you very much!!
     
    spiney199 likes this.