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

Resolved IBaker.AddComponent<T>(in T)' is obsolete?

Discussion in 'Entity Component System' started by Heptagram064, Mar 23, 2023.

  1. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    Just updated my project to Enteties 1.0.0 pre 65,

    It seems to fix all unity side startup errors, but now i get this one saying;
    'IBaker.AddComponent<T>(in T)' is obsolete: 'Use the version of the function with the explicit Entity parameter (RemovedAfter Entities 1.0)'

    I am verry new to unity DOTS, and dont realley know what this means. There apears to be no fix the IDE suggests, nor any info on the web mentioning it.

    here is my code:
    Code (CSharp):
    1. using Unity.Entities;
    2. using UnityEngine;
    3.  
    4. // The authoring "Unity Component"
    5. public class OutlineAuthoringComponents_SettingsAuthering : MonoBehaviour {
    6.     public bool useLightAccents;
    7.     public bool useLightModefier;
    8.     public bool useDepthModefier;
    9. }
    10.  
    11. // Bake the authoring Unity Component into a ecs component
    12. public class OutlineAutheringComponents_SettingsBaker : Baker<OutlineAuthoringComponents_SettingsAuthering>
    13. {
    14.     public override void Bake(OutlineAuthoringComponents_SettingsAuthering authoring)
    15.     {
    16.         AddComponent(new OutlineAuthoringComponents_Settings
    17.         {
    18.             useLightAccents = authoring.useLightAccents,
    19.             useLightModefier = authoring.useLightModefier,
    20.             useDepthModefier = authoring.useDepthModefier
    21.         });
    22.     }
    23. }
    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. public struct OutlineAuthoringComponents_Settings : IComponentData
    4. {
    5.     public bool useLightAccents;
    6.     public bool useLightModefier;
    7.     public bool useDepthModefier;
    8. }
    Does anyone know how to fix this?
     
    frankfringe likes this.
  2. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    just need to get the entity using
    GetEntity(TransformsFlags)
    and then use that entity with each
    Code (CSharp):
    1. AddComponent(entity, yourComponent)
    in bakers.
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,655
    Because it's not what been suggested to you:
    GetEntity(TransformsFlags) != GetEntity()

    Isn't IDE didn't show you what to use for obsolete things?
    upload_2023-3-24_13-37-42.png
     
  4. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    Seems a bit redundant to need to add 2 lines, to do the exact same as before, but whatever floats.
    Code (CSharp):
    1. using Unity.Entities;
    2. using UnityEngine;
    3.  
    4. // The authoring "Unity Component"
    5. public class OutlineAuthoringComponents_SettingsAuthering : MonoBehaviour {
    6.     public bool useLightAccents;
    7.     public bool useLightModefier;
    8.     public bool useDepthModefier;
    9. }
    10.  
    11. // Bake the authoring Unity Component into a ecs component
    12. public class OutlineAutheringComponents_SettingsBaker : Baker<OutlineAuthoringComponents_SettingsAuthering>
    13. {
    14.     public override void Bake(OutlineAuthoringComponents_SettingsAuthering authoring)
    15.     {
    16.         // Prequisites to baking
    17.         TransformUsageFlags transformUsageFlags = new TransformUsageFlags();
    18.         Entity entity = this.GetEntity(transformUsageFlags);
    19.         // Bake the damn thing
    20.         AddComponent(entity, new OutlineAuthoringComponents_Settings
    21.         {
    22.             useLightAccents = authoring.useLightAccents,
    23.             useLightModefier = authoring.useLightModefier,
    24.             useDepthModefier = authoring.useDepthModefier
    25.         });
    26.     }
    27. }
    Warning seems gone now.
     
  5. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    Deleted that comment 10 seconds after posting lol. Thx for quick reply tho.
    Code (CSharp):
    1. TransformUsageFlags transformUsageFlags = new TransformUsageFlags();
    2. Entity entity = this.GetEntity(transformUsageFlags);
    seems to do it
     
    Last edited: Mar 24, 2023
    sudunity12 likes this.
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,655
    TransformUsageFlags
    is just
    enum
    flags, you don't need to
    new
    it

    Code (CSharp):
    1. var e = GetEntity(authoring, TransformUsageFlags.NonUniformScale | TransformUsageFlags.Dynamic);
     
    tsukimi likes this.
  7. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    Makes more sense
     
    azmi_unity and Stormer2020 like this.