yasirkula/UnityAssetUsageDetector

Assets referenced by polymorphism [SerializeReference] not found

Staarter opened this issue · 2 comments

Description of the bug

Assets that are referenced by polymorphism using the tag [SerializeReference] are not found by AUD.

Reproduction steps

  • Create scripts using these class :
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class ContainerBase { }

[System.Serializable]
public class ContainerGO : ContainerBase
{
	public GameObject go;
}

[CreateAssetMenu(fileName ="AUD_SerializeReference", menuName = "AUD_SerializeReference")]
public class DebugAUD_SerializeReference : ScriptableObject
{
	[SerializeReference] public List<ContainerBase> test = new List<ContainerBase>();

	private void OnValidate()
	{
		// Add an empty element here: we cannot do it in inspector by default
		test.Add(new ContainerGO());
	}
}

[CreateAssetMenu(fileName ="AUD_Default", menuName = "AUD_Default")]
public class DebugAUD_Default : ScriptableObject
{
	public List<ContainerGO> test = new List<ContainerGO>();
}
  • Create the two ScriptableObject 'AUD_Default' & 'AUD_SerializeReference'.
  • Add a prefab gameObject into theses two 'test' fields.
  • Try to search this prefab using the AUD window
  • Only the ScriptableObject 'AUD_Default' will be found as using the prefab.

image_2023-02-21_182622092

Platform specs

Please provide the following info if this is a Unity 3D repository.

  • Unity version: 2020.3.16
  • Platform: Windows
  • How did you download the plugin: Asset Store (the asset is up to date)

Additional info

I know that Unity have made changes about SerializeField in 2021 or 2022, the serialization can be changed, but I am using 2020..

Thank you for bringing this to my attention! I'll include the fix in the next release but in the meantime, you can apply the fix yourself by changing these lines:

case SerializedPropertyType.ManagedReference:
propertyValue = GetRawSerializedPropertyValue( iterator ) as Object;
searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
enterChildren = false;
break;

As follows:

case SerializedPropertyType.ManagedReference:
	object managedReferenceValue = GetRawSerializedPropertyValue( iterator );
	propertyValue = managedReferenceValue as Object;
	searchResult = SearchObject( PreferablyGameObject( managedReferenceValue ) );
	enterChildren = false;
	break;

Thank you for your reply!
This fix works like a charm, good job.