Skip to content

Fix 'Can't destroy Transform component' play error #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Assets/RuntimeDebugDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ private void Awake()
{
CheckInitialized();

#if UNITY_EDITOR && UNITY_2017_4_OR_NEWER
UnityEditor.EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
#endif
return;
}

Expand Down Expand Up @@ -422,6 +425,9 @@ private void OnDestroy()
_AlwaysBatch.Dispose();
_ZTestBatch.Dispose();

#if UNITY_EDITOR && UNITY_2017_4_OR_NEWER
UnityEditor.EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
#endif
return;
}

Expand All @@ -433,6 +439,17 @@ private void Clear()

return;
}

#if UNITY_EDITOR && UNITY_2017_4_OR_NEWER
private void OnPlayModeStateChanged(UnityEditor.PlayModeStateChange playMode)
{
if (playMode == UnityEditor.PlayModeStateChange.ExitingPlayMode)
{
// hack to avoid 'Can't destroy Transform component' error due to parent hide flags.
transform.parent = null;
}
}
#endif
#endregion

#region Draw Lines
Expand Down