#Companion GameObject is not rendered

1 messages · Page 1 of 1 (latest)

teal pebble
#

Hi, I am trying to add a Companion Gameobject, these are the components:

public class AddTrackingGO : IComponentData
{
    public GameObject Prefab;
}

public class TrackingGO : IComponentData, IDisposable, ICloneable
{
    public GameObject Value;

    public void Dispose()
    {
        UnityEngine.Object.Destroy(Value);
    }

    public object Clone()
    {
        return new TrackingGO
        {
            Value = UnityEngine.Object.Instantiate(Value)
        };
    }
}

The system just executes

        Entities.ForEach((Entity e, AddTrackingGO addTrackingGo, in LocalTransform transform) =>
        {
            
            var go = UnityEngine.GameObject.Instantiate(addTrackingGo.Prefab, transform.Position, transform._Rotation);

            EntityManager.AddComponentData(e, new TrackingGO
            {
                Value = go
            });

            EntityManager.RemoveComponent<AddTrackingGO>(e);
        }).WithStructuralChanges().Run();

It seems like the adding of the Gameobject is working (I see a new GO in my scene). The following problems occur:

  1. The Gameobject is not rendered. I see the new GO in the scene (and even its transform is updated by another of my systems to match the entity transform). But I only see the GO rendered after I exit play mode (is this because the GO is in the same Subscene as the player object which is only for entities?)
  2. The Gameobject is not deleted after I exit play mode - Actually, that is when it becomes visible to me.

Any help is highly appreciated!