Hi folks,
Strange thing! I use the same code, one in Monobehavior and the other in JobComponentSystem.
Monobehavior works like a charm, but not in the other.
The error message I get:
: A component with type:RenderMesh has not been added to the entity.
Unity.Entities.EntityComponentStore.AssertEntityHasComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType componentType) (at Library/PackageCache/com.unity.entities@0.11.2-preview.1/Unity.Entities/EntityComponentStoreDebug.cs:271)
…
Unity.Entities.DefaultWorldInitialization:AddSystemsToRootLevelSystemGroups(World, Type[ ]) (at Library/PackageCache/com.unity.entities@0.11.2-preview.1/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs:127)
Unity.Entities.DefaultWorldInitialization:Initialize(String, Boolean) (at Library/PackageCache/com.unity.entities@0.11.2-preview.1/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs:106)
Unity.Entities.AutomaticWorldBootstrap:Initialize() (at Library/PackageCache/com.unity.entities@0.11.2-preview.1/Unity.Entities.Hybrid/Injection/AutomaticWorldBootstrap.cs:15)
Here is my code:
public class Management : JobComponentSystem
{
public bool updatetrue = true;
public List<SList> sList = new List<SList>();
private EntityManager sEntityManager;
Mesh sMesh;
Material sGlow1;
Material sGlow2;
protected override void OnCreate()
{
sMesh = Resources.Load<Mesh>("Meshs/SMesh");
sGlow1 = Resources.Load<Material>("Materials/SGlow");
sGlow2 = Resources.Load<Material>("Materials/PinkGlow");
// Fill list with Query.
// Here is some code.
sEntityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
foreach (SList singleship in sList)
{
CreateSEntity(singles);
}
}
void CreateSEntity(SList sShip)
{
Entity sEntity = sEntityManager.CreateEntity();
#if UNITY_EDITOR
sEntityManager.SetName(sEntity, "S_Player: " + singleS.playerName + "/" + singleS.shipId);
#endif
sEntityManager.AddComponentData(sEntity, new PlayerComponent
{ playerName = singleS.playerName });
sEntityManager.AddComponentData(sEntity, new SEntityComponent
{ sId = singleS.sId });
sEntityManager.AddComponentData(sEntity, new Translation
{ Value = new float3(singleS.currentX, singleS.currentY, singleS.currentZ) });
myRandom = Random.Range(0f, 10f);
if (myRandom > 5)
{
// This causes the error depending on random
sEntityManager.SetSharedComponentData(sEntity, new RenderMesh
{ mesh = sMesh, material = sGlow1 });
}
else
{
// This causes the error depending on random
sEntityManager.SetSharedComponentData(sEntity, new RenderMesh
{ mesh = sMesh, material = sGlow2 });
}
sEntityManager.AddComponentData(sEntity, new LocalToWorld { });
sEntityManager.AddComponentData(sEntity, new RenderBounds { });
sEntityManager.AddComponentData(sEntity, new Rotation { });
}
Somebody has an idea, please?
Thanks
Slarti