Search Unity

Unity ECS Lights

Discussion in 'Entity Component System' started by Gaaammmler, Jul 25, 2019.

  1. Gaaammmler

    Gaaammmler

    Joined:
    Apr 10, 2018
    Posts:
    16
    Hello Guys,

    i want to use lights in ecs, but if i add the conversion script Convert to entity, there is no light.
    Can anyone explain me how i get light in a pure ecs way or is now no way to implement lights in pure ecs?
     
  2. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    966
    I was asking this some time ago, the ECS team is aware of it and it's coming but right now, you'd have to spawn them yourself as gameobject which follows an entity. Pretty easy as it's just a matter of getting the followed entity translation and add some offset in a MonoBehaviour Update.
     
    Antypodish likes this.
  3. Gaaammmler

    Gaaammmler

    Joined:
    Apr 10, 2018
    Posts:
    16
    So the best way now is to add them as gameobjects and translate the transfrom in a system with the entity transform to the right position? I thought maybe i didnt notice something here for pure ecs way, thx for the reply. :)
     
    deus0 likes this.
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Some hybrid solution can be good for now, to manipulate light GameObject. With mind for later change into pure, when option get available.
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Support for conversion of lights is part of the next release should be early next week.
     
  6. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Omg so pumped for lights! My world is so dim without sweet sweet lights (pun intended). Really looking forward to seeing how many lights I can have flying around in lwrp!
     
  7. Gaaammmler

    Gaaammmler

    Joined:
    Apr 10, 2018
    Posts:
    16
    I tested the new Package but get the following error if i add Convert To Entity: Convert and Destroy

    NullReferenceException: Object reference not set to an instance of an object
    Unity.Rendering.LightConversion.<OnUpdate>b__0_0 (UnityEngine.Light unityLight) (at Library/PackageCache/com.unity.rendering.hybrid@0.1.0-preview/Unity.Rendering.Hybrid/LightConversion.cs:46)


    ok got it work, i'm dump and installed the High Definiton RP, so i removed it and it worked :)
     

    Attached Files:

    Last edited: Jul 30, 2019
  8. Levr01

    Levr01

    Joined:
    Jun 6, 2017
    Posts:
    26
    Im try this code but with Lights dosnt work ;( This works only with objects with renderers
    Code (CSharp):
    1. private void Start()
    2.     {
    3.         List<Light> LTS = new List<Light>();
    4.         var lights = FindObjectsOfType(typeof(Light));
    5.         foreach(Object o in lights)
    6.         {
    7.             LTS.Add((Light)o);
    8.         }
    9.  
    10.          EntityManager entityManager = World.Active.EntityManager;
    11.         EntityArchetype entityArchetype = entityManager.CreateArchetype
    12.                 (
    13.                 typeof(Translation),
    14.                 typeof(Rotation),
    15.                 typeof(NonUniformScale),
    16.                 typeof(LightComponent),
    17.                 typeof(Light)
    18.                 );
    19.  
    20.         entities = new NativeArray<Entity>(LTS.Count, Allocator.Temp);
    21.         entityManager.CreateEntity(entityArchetype, entities);
    22.  
    23.  
    24.  
    25.         for (int i = 0; i < entities.Length; i++)
    26.         {
    27.             Entity entity = entities[i];
    28.             entityManager.SetComponentData(entity, new Translation { Value = new float3(LTS[i].gameObject.transform.position.x, LTS[i].gameObject.transform.position.y, LTS[i].gameObject.transform.position.z) });
    29.             entityManager.SetComponentData(entity, new Rotation { Value = new Quaternion(LTS[i].gameObject.transform.rotation.x, LTS[i].gameObject.transform.rotation.y, LTS[i].gameObject.transform.rotation.z, LTS[i].gameObject.transform.rotation.w) });
    30.             entityManager.SetComponentData(entity, new NonUniformScale { Value = new float3(LTS[i].gameObject.transform.localScale.x, LTS[i].gameObject.transform.localScale.y, LTS[i].gameObject.transform.localScale.z) });
    31.  
    32.             entityManager.SetComponentData(entity, new LightComponent
    33.             {
    34.                 type = LTS[i].type,
    35.                 range = LTS[i].range,
    36.                 spotAngle = LTS[i].spotAngle,
    37.                 color = LTS[i].color,
    38.                 intensity = LTS[i].intensity,
    39.                 renderingLayerMask = LTS[i].renderingLayerMask,
    40.                 cullingMask = LTS[i].cullingMask,
    41.             });
    42.         };
    43.  
    44.         entities.Dispose();
    45.  
    46.         foreach (Light o in LTS)
    47.         {
    48.             o.enabled = false;
    49.         }
    50.     }