Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

HD Additional Camera Data and Convert to Entity

Discussion in 'Entity Component System' started by RoughSpaghetti3211, May 14, 2020.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,695
    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
    Screen Shot 2020-05-13 at 8.29.11 PM.png
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,993
    You can use Convert and Destroy with HYBRID_ENTITIES_CAMERA_CONVERSION defined. Hybrid Renderer is smart enough to account for HD Additional Camera Data.
     
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,695
    Do you have a simple example It does not seem to be working, Maybe subscenes not supported ?
     
    Last edited: May 14, 2020
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,993
    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.
     
  5. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,695
    Is the intend workflow to use

    Code (CSharp):
    1.  
    2. public class CameraProxyConversion : MonoBehaviour, IConvertGameObjectToEntity
    3. {
    4.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    5.     {
    6. #if HYBRID_ENTITIES_CAMERA_CONVERSION
    7. #endif
    8.     }
    9. }
    10.  
    Then
    Code (CSharp):
    1.  
    2. public class CameraConversionSystem : GameObjectConversionSystem
    3. {
    4.     protected override void OnUpdate()
    5.     {
    6.         Entities.ForEach((Camera camera) =>
    7.             {
    8.                 Entity eCamera = GetPrimaryEntity(camera);
    9.                 Debug.Log("Camera Conversion");
    10.                 EntityManager.AddComponentData<CopyTransformFromGameObject>(eCamera, new CopyTransformFromGameObject());
    11.                 EntityManager.AddComponentData<CameraMainComponents>(eCamera, new CameraMainComponents());
    12.                 EntityManager.AddComponentData<CameraLodComponents>(eCamera, new CameraLodComponents()
    13.                 {
    14.                     CameraLastPosition = camera.transform.position
    15.                 });
    16.             });
    17.     }
    18. }
    19.  
    20.  
    Feels like im making this more complex than needed ?
     
  6. wg-siggig

    wg-siggig

    Joined:
    Mar 17, 2020
    Posts:
    36
    Afaik converting the camera in a subscene is still not supported, but should work outside one.
     
  7. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,993
    This code already exists in Hybrid Renderer. You should not have to do anything other than add the Scripting Define Symbol to your project.
    Code (CSharp):
    1. #if HYBRID_ENTITIES_CAMERA_CONVERSION
    2.     [WorldSystemFilter(WorldSystemFilterFlags.HybridGameObjectConversion)]
    3.     public class CameraConversionSystem : GameObjectConversionSystem
    4.     {
    5.         protected override void OnUpdate()
    6.         {
    7.             Entities.ForEach((Camera camera) =>
    8.             {
    9.                 AddHybridComponent(camera);
    10.             });
    11.  
    12. #if HDRP_7_0_0_OR_NEWER
    13.             Entities.ForEach((HDAdditionalCameraData data) =>
    14.             {
    15.                 AddHybridComponent(data);
    16.             });
    17. #endif
    18.  
    19. #if URP_7_0_0_OR_NEWER
    20.             Entities.ForEach((UniversalAdditionalCameraData data) =>
    21.             {
    22.                 AddHybridComponent(data);
    23.             });
    24. #endif
    25.         }
    26.     }
    27. #endif
     
  8. wg-siggig

    wg-siggig

    Joined:
    Mar 17, 2020
    Posts:
    36
    Yes, I know :) 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)
     
  9. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,993
    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.
     
    wg-siggig likes this.
  10. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,695
    Thank you ripping it out of subScene and adding HYBRID_ENTITIES_CAMERA_CONVERSION I can now see the entity
     
    wg-siggig likes this.