est005
est005

Reputation: 138

Unity Entities not rendering in play mode

I have tried to Instantiate an entity using code:

blobAssetStore = new BlobAssetStore();
GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(defaultWorld,blobAssetStore);
Entity entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPrefab, settings);      
entityManager.SetComponentData(entity, new Translation { Value = position });

I have tried using the ConvertToEntity script. I have also created a subscene, all three methods are not rendering. I can see the entities in the Entity Debugger all the entities have a Translation, and the relevant render components, everything looks good. These are the ECS packages I have installed:

Using Unity 2020.1.0b12.3931

Any suggestions and ideas are welcome

Upvotes: 1

Views: 4056

Answers (1)

est005
est005

Reputation: 138

I found the issue, it seems that even though this line of code creates an entity :

Entity entityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPrefab, settings);

It does not set the LocalToWorld coordinates as below: Snip of Enity Prefab LocalToWorld

If I call Instantiate after the above line, with the previously created entity:

Entity entity = entityManager.Instantiate(entityPrefab);

Then the LocalToWorld is set correct to the Translation position passed in: enter image description here

Even if I try and set the LocalToWorld component to the correct position using this:

 entityManager.SetComponentData(entityPrefab, new LocalToWorld { Value = new float4x4(quaternion.identity, position) });

It still does not show, my only guess at the moment is that it has a Prefab component attached to it, as shown below:

enter image description here

Although even trying to remove this component does not show the entity created:

 entityManager.RemoveComponent(entityPrefab, typeof(Prefab));

I am doing some more research on why this is and will post any finding here. The complete code now looks like this :

private void InstantiateEntity(float3 position)
{
    blobAssetStore = new BlobAssetStore();
    GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(defaultWorld, blobAssetStore);        
    Entity entityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPrefab, settings);
    Entity entity = entityManager.Instantiate(entityPrefab);
    entityManager.SetComponentData(entity, new Translation { Value = position });        
}

I hope this helps someone in future.

Upvotes: 2

Related Questions