HD Additional Camera Data and Convert to Entity

Just wondering how do I conver a camera in HDRP to and entity with Covert to Entity Script.

Can’t remove Camera because HDAdditionalCameraData (Script) depends on it.

But im converting and injecting ? What am i missing here

You can use Convert and Destroy with HYBRID_ENTITIES_CAMERA_CONVERSION defined. Hybrid Renderer is smart enough to account for HD Additional Camera Data.

Do you have a simple example It does not seem to be working, Maybe subscenes not supported ?

I don’t use subscenes for the camera in my project. I only use subscenes for pure entities which so far has given me good results.

Is the intend workflow to use

public class CameraProxyConversion : MonoBehaviour, IConvertGameObjectToEntity
{
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
#if HYBRID_ENTITIES_CAMERA_CONVERSION
#endif
    }
}

Then

public class CameraConversionSystem : GameObjectConversionSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach((Camera camera) =>
            {
                Entity eCamera = GetPrimaryEntity(camera); 
                Debug.Log("Camera Conversion");
                EntityManager.AddComponentData<CopyTransformFromGameObject>(eCamera, new CopyTransformFromGameObject());
                EntityManager.AddComponentData<CameraMainComponents>(eCamera, new CameraMainComponents());
                EntityManager.AddComponentData<CameraLodComponents>(eCamera, new CameraLodComponents()
                {
                    CameraLastPosition = camera.transform.position
                });
            }); 
    }
}

Feels like im making this more complex than needed ?

Afaik converting the camera in a subscene is still not supported, but should work outside one.

This code already exists in Hybrid Renderer. You should not have to do anything other than add the Scripting Define Symbol to your project.

#if HYBRID_ENTITIES_CAMERA_CONVERSION
    [WorldSystemFilter(WorldSystemFilterFlags.HybridGameObjectConversion)]
    public class CameraConversionSystem : GameObjectConversionSystem
    {
        protected override void OnUpdate()
        {
            Entities.ForEach((Camera camera) =>
            {
                AddHybridComponent(camera);
            });

#if HDRP_7_0_0_OR_NEWER
            Entities.ForEach((HDAdditionalCameraData data) =>
            {
                AddHybridComponent(data);
            });
#endif

#if URP_7_0_0_OR_NEWER
            Entities.ForEach((UniversalAdditionalCameraData data) =>
            {
                AddHybridComponent(data);
            });
#endif
        }
    }
#endif

Yes, I know :slight_smile: but if you try using this in a subscene the camera goes black as soon as you close the subscene (where the GOs are not present anymore)

Sorry. That reply was to @francois85 and I know subscenes don’t work. I don’t put the camera in a subscene have no reason to at the moment.

1 Like

Thank you ripping it out of subScene and adding HYBRID_ENTITIES_CAMERA_CONVERSION I can now see the entity

1 Like