Skip to content

Commit

Permalink
Fixed Inspector editors rendered together with [HideInInspector] for …
Browse files Browse the repository at this point in the history
…the whole class. Unity 2022.1 and later behaves strange when hideFlags is changed in the editor OnEnable.
  • Loading branch information
nmalg committed Oct 12, 2022
1 parent 1f3fd7d commit f8b4807
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions AGXUnity/AttachmentPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ protected override bool Initialize()
return true;
}

protected virtual void Reset()
{
hideFlags |= HideFlags.HideInInspector;
}

private AttachmentPair()
{
}
Expand Down
5 changes: 5 additions & 0 deletions AGXUnity/ElementaryConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,10 @@ protected override void OnDestroy()

base.OnDestroy();
}

protected virtual void Reset()
{
hideFlags |= HideFlags.HideInInspector;
}
}
}
5 changes: 5 additions & 0 deletions AGXUnity/MassProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ protected override bool Initialize()
return true;
}

protected virtual void Reset()
{
hideFlags |= HideFlags.HideInInspector;
}

/// <summary>
/// Finds the native rigid body instance this mass properties belongs to.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions AGXUnity/Route.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ protected override void OnDestroy()
base.OnDestroy();
}

protected virtual void Reset()
{
hideFlags |= HideFlags.HideInInspector;
}

private bool TryInsertAtIndex( int index, T node )
{
// According to List documentation having index == m_nodes.Count is
Expand Down
5 changes: 5 additions & 0 deletions AGXUnity/Utils/OnSelectionProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ public ScriptComponent Component
get { return m_component; }
set { m_component = value; }
}

protected virtual void Reset()
{
hideFlags |= HideFlags.HideInInspector;
}
}
}
11 changes: 9 additions & 2 deletions Editor/AGXUnityEditor/InspectorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,15 @@ private void OnEnable()
m_numTargetGameObjectsTargetComponents = m_targetGameObjects.Sum( go => go.GetComponents( m_targetType ).Length );

// Entire class/component marked as hidden - enable "hide in inspector".
if ( this.target.GetType().GetCustomAttributes( typeof( HideInInspector ), false ).Length > 0 )
this.target.hideFlags |= HideFlags.HideInInspector;
// NOTE: This will break Inspector rendering in 2022.1 and later because changing
// hideFlags here results in a destroy of all editors and the editors that
// should be visible are enabled again but never rendered by Unity.
// SOLUTION: Add hideFlags |= HideFlags.HideInInspector in Reset method of the class
// that shouldn't be rendered in the Inspector.
if ( this.targets.Any( t => !t.hideFlags.HasFlag( HideFlags.HideInInspector ) ) && m_targetType.GetCustomAttribute<HideInInspector>( false ) != null ) {
foreach ( var t in this.targets )
t.hideFlags |= HideFlags.HideInInspector;
}

ToolManager.OnTargetEditorEnable( this.targets, this );
}
Expand Down

0 comments on commit f8b4807

Please sign in to comment.