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

Bug public override void OnGUI Causes SerializedObject target has been destroyed.

Discussion in 'Editor & General Support' started by MohamedTun, Nov 29, 2023.

  1. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    51
    This Error appears in unity 2022 LTS+ but works fine in the 2021 LTS !
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class MyAttribute : PropertyAttribute
    4. {
    5. }
    6.  
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. [CustomPropertyDrawer(typeof(MyAttribute))]
    5. public class MyAttribute_Drawer : PropertyDrawer {
    6.  
    7.  
    8.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
    9.  
    10.      
    11.         // Dosen't matter if I change anything here or leave It empty always when I reload the scene and the gameObject
    12.         // that have [MyAttribute] [SerializeField] AnyVariable anyVariable; is showing in the inspector I get that Error
    13.         // and the editor pause!
    14.  
    15.     }
    16.  
    17. }
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class TEST : MonoBehaviour {
    4.     [MyAttribute][SerializeField] private int test;
    5.     // When this GameObject is showing in the inspector and I reload the scene I get this error:
    6.     // SerializedObject target has been destroyed.
    7.     // UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    8. }