I added “Convert to Entity” script on a Player with conversion as “Convert And Inject Game Object”
Then added a monobheaviour with IConvertGameObjectToEntity
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
MoveObjSpeed moveObj = new MoveObjSpeed{speed = 10};
dstManager.AddComponentData(entity, moveObj);
// PlayerTag myTag = new PlayerTag { };
dstManager.AddComponent(entity, typeof(PlayerTag));
}
after that, I created empty Player tag component Data and a move speed component data.
Now I added JobComponent like this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
using Unity.Mathematics;
using Unity.Jobs;
public class MoveSYstem : JobComponentSystem
{
[RequireComponentTag(typeof(PlayerTag))] //PlayerTag is empty
struct MoveDataSystem : IJobForEach<Translation, Rotation, MoveObjSpeed>
{
public void Execute(ref Translation pos,ref Rotation rot, ref MoveObjSpeed speedObj)
{
Debug.Log(pos.Value); //this is showing player's initital value
rot.Value = quaternion.Euler(10, 10, 10);
pos.Value = new float3(3, 3, 3);
Debug.Log(pos.Value); //it is showing updated value
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var moveDatsaSystem = new MoveDataSystem
{
};
// Debug.Log("is it");
return moveDatsaSystem.Schedule(this, inputDeps);
}
}
I get the two Debug.Log with the player’s previous and new position. But in the editor, I can’t see the player changing its position.
Yeah you are right, i was forgetting that ComponentDataProxy<> enforces GameObjectEntity.
Then you either leave it like that and ignore the message, but bear in mind that it will be deprecated and removed soon or later, or just create a component to convert it like this:
public class MyCopyTransformToGameObject : MonoBehaviour, IConvertGameObjectToEntity {
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) {
dstManager.AddComponentData(entity, new Unity.Transforms.CopyTransformToGameObject());
}
}
Functionally there’s no difference for tag components. One code path might be faster than the other, but it is difficult to tell which from looking at the internals. You’d have to profile and see.
For non-tag components, the first method lets you initialize values while the second just adds a default of the type but lets you work with types at runtime.