I would love to be able to do GO.AddComponent(). I am work on a hybrid ECS SO NPC spawner system and it would save sometime not having to write a Custom Authoring Component.
1 Like
I can propose this untested work around :
Utility :
internal static Type GetAuthoringComponentTypeFromIComponentData(Type IComponentDataType)
{
string[] AssemblyQualifiedNameAttributes = IComponentDataType.AssemblyQualifiedName.Split(',');
string AuthoringComponentAssemblyQualifiedName = $"{IComponentDataType.Name}Authoring";
for (int i =1;i< AssemblyQualifiedNameAttributes.Length;i++)
{
AuthoringComponentAssemblyQualifiedName = $"{AuthoringComponentAssemblyQualifiedName}, {AssemblyQualifiedNameAttributes[i]}";
}
Type AuthoringComponentType = Type.GetType(AuthoringComponentAssemblyQualifiedName);
AddComponentIfMissing(AuthoringComponentType);
return AuthoringComponentType;
}
Usage :
GameObject gameObject = new GameObject();
gameObject.AddComponent(GetAuthoringComponentTypeFromIComponentData(typeof(IComponentData));
1 Like
Quick test and no go. I might attempt to get this working later.