Apologies if this has been posted in some capacity before - it has proven remarkably difficult to find an answer to this, Google seems to think I’m only asking about one or the other, over an hour of searching and has yielded very little in terms of up-to-date information with Entities and practically nothing on these hybrid approaches in >v1.0.
I have a project currently implemented in terms of GameObjects. Among these is a GameObject prefab that contains a number of further components, such as networking, mesh rendering, some little scripts, but crucially a MeshCollider. My goal is to move the MeshCollider and other physics processing parts over to DOTS to leverage Unity Physics.
So far, I have managed to set up physics authoring for my static objects (eg. the map) and dynamic objects (eg. my prefabs). This includes swapping the MeshCollider out for a PhysicsCollider, conditionally setting up PhysicsVelocity and PhysicsMass, etc.
The part I am stuck on is the runtime instantiation of these prefabs. As far as I can see, where I previously had a simple GameObject.Instantiate(prefab), I now need to additionally have something create an Entity and then somehow couple these two such that the GameObject copies the transform of the Entity (as the transform is required by other GameObject components). I have written a sync system to do this:
ForEach((ref LocalTransform localTransform, in GameObjectRef gameObjectRef) => //copy pos, rot
but can’t figure out how to actually add the GameObjectRef component to anything:
public struct GameObjectRef : IComponentData
{
public GameObject GameObject;
}
//...
//meanwhile, in my spawner system
var gameObject = Object.Instantiate(prefab);
ecb.AddComponent(entity, new GameObjectRef
{
GameObject = gameObject
});
as GameObject is not a native type.
I feel like I might be going about this all wrong, if there is a generally accepted as sane way of managing these hybrid cases I’d love to know about it.
Regards