cannot convert from 'Unity.Entities.Entity' to 'Unity.Entities.EntityQuery'
I get two errors when I am compiling the code and I cannot seem to figure out why, I am new to Entities so this is my attempt to try to figure them out.
Below is my code:
public class BootStrap
{
public static EntityArchetype PlayerUnitArchType;
private static Mesh cubeRenderer; //renderer for each of the entities you want to render in scene
private static EntityManager entityManager;
//need initialize and initialize with scene in bootstrap
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void Initialize()
{
//This method creates archetypes for entities we will spawn frequently in this game
//Archetypes are optional but can speed up entity spawing substantially
entityManager = World.Active.EntityManager;//handels all entity manageing
//archtype for things that are used multiple times
PlayerUnitArchType = entityManager.CreateArchetype(typeof(Translation),
typeof(Rotation),
typeof(MoveSpeed),
typeof(PlayerInputComponent) );
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
public static void InitializeWithScene()
{
cubeRenderer = GetLookFromPrototype("CubePrototype");//make cube prototype in scene
StartRTSGame();
}
public static void StartRTSGame()
{
for (int i = 0; i< 3; i++)
{
Entity playerUnit = entityManager.CreateEntity(PlayerUnitArchType);
//set pos .5 away from each other to give space
entityManager.SetComponentData(playerUnit, new Translation { Value = new float3(i * 5, 0.5f, 0) });
//data that doesn't change often, genrally were render stuff goes
entityManager.AddSharedComponentData(playerUnit, cubeRenderer);
}
}
public static Mesh GetLookFromPrototype(string protoName)
{
var proto = GameObject.Find(protoName);
var result = proto.GetComponent<RenderMesh>().mesh;
//obect.Destroy(proto);
return result;
}
The two errors I get are below:
ArgumentException: GetComponent requires that the requested component 'RenderMesh' derives from MonoBehaviour or Component or is an interface. UnityEngine.GameObject.GetComponent[T] ()
Assets\RTS_ECS_Tutorial\Scripts\BootStrap.cs(50,50): error CS1503: Argument 1: cannot convert from 'Unity.Entities.Entity' to 'Unity.Entities.EntityQuery'
I am very new to ECS and am trying to learn it so any comments about my code would be appreciated.
The first error is caused by this line
var result = proto.GetComponent<Render$$anonymous$$esh>().mesh;
It should be
var result = proto.GetComponent<$$anonymous$$eshRenderer>().mesh;
The 2nd error however, is strange, because AddSharedComponentData
accepts an Entity
public void AddSharedComponentData<T>(Entity entity, T componentData)
where T : struct, ISharedComponentData
I'm having the same problem as your #2 error with entity$$anonymous$$anager.SetSharedComponentData(), which definitely has a form of (Entity, ComponentData) per docs and metadata, but it won't compile saying it can't convert it to an EntityQuery. It's like the compiler can't see the overloads... WTH??
Same problem, even if I switch to the Unity.Entities.EntityQuery it says Argument 1: cannot convert from 'Unity.Entities.EntityQuery' to 'Unity.Entities.Entity' :)