Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug Spline field in a nested class throws exception in inspector.

Discussion in '2022.1 Beta' started by MechaWolf99, Mar 11, 2022.

  1. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    294
    If you have a Spline field in a class that is a field of a MonoBehaviour, the inspector will throw exceptions when trying to view the contents of the Spline field.

    Code (CSharp):
    1. public class SplineExample : MonoBehaviour
    2. {
    3.     [SerializeField] private SplineHolder _splineHolder;
    4. }
    5.  
    6. [System.Serializable]
    7. public class SplineHolder
    8. {
    9.     [SerializeField] private Spline _spline;
    10. }
    The reason for this is because you are using a naïve implementation to get the Spline value from a SerializedProperty and directly using the property path to get the field info and passing the SerializedObject's target as the object for the GetField(..).

    What you need to do is split up the path and walk over the whole thing getting each field along the way and using the value from the previous field to get the value of the next. I have a implementation myself that supports both arrays/lists and SerializeReference if you want to take a look at it.
    Github Repo (MIT)

    Case 1410152
     
    Last edited: Mar 14, 2022
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334