I’ve been trying to get a simple hybrid ecs implementation to work. Simply moving a sprite around the screen using hybrid ecs: ecs for the input and logic, the old system for the sprite-renderer.
I have a simple player object, with a speed and input component, as well as a sprite renderer and the “Convert To Entity” script set to inject.
However, when I use the arrows to move around, only the entity part seems to get updated, not the game-object side of the hybrid ecs. The initial position (-0.06, -4) is being copied into the entity, but the entity’s position isn’t copied back to the game-object.
My system seems to work fine, as shown here:
The translation is being updated, so my input system updates that fine based on my speed and input components. That updated translation just isn’t reflected in the game-object’s position.
What am I missing? Do I have to add another component to my player object?
I’m using Unity 2019.1.11f1, and the latest entities package 0.0.12.
You need to add CopyTransformToGameObject component to the entity you’ve converted from prefab.
Either via conversion component (from classic / hybrid, or via ECS EntityManager)
Here’s an example of how I do my conversion for Camera ↔ Entity:
/// <summary>
/// Converts camera object to the entity
/// </summary>
[RequiresEntityConversion]
[RequireComponent(typeof(Camera))]
public class CameraConverter : MonoBehaviour, IConvertGameObjectToEntity {
[SerializeField]
private Camera _camera = default;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) {
// you can as well add some components here, like movement etc
dstManager.AddComponentData(entity, new CopyTransformToGameObject());
}
#if UNITY_EDITOR
protected virtual void OnValidate() {
_camera = GetComponent<Camera>();
}
#endif
}
(Attach that MonoBehaviour to the GO with Convert component)
That does seem to fix the problem, however it also makes an error show up that I should remove the Game Object Entity script (which is needed for the Copy Transform To Game Object script):
Partly off topic, I read about the proxy stuff before, with the “Game Object Entity” script, but it seems like that’s the old way of doing stuff. Like now there is the conversion method which is the most recent and recommended way of doing ECS/hybrid ECS now. Is that right?