Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. We are looking for feedback on the naming of a new user research platform that we are working on.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[GenerateAuthoringComponent] is it available yet?

Discussion in 'Data Oriented Technology Stack' started by Arowx, Sep 29, 2019.

  1. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    7,552
    The Unite Keynote mentions the reduction of boilerplate with this compiler [tag], is it available yet?
     
    Last edited: Sep 29, 2019
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,107
    Not yet, probably will soon, cause they on b5 and it’s next beta release, I think it will be public together with new DOTS sample.
     
    MNNoxMortem and Opeth001 like this.
  3. pal_trefall

    pal_trefall

    Joined:
    Feb 5, 2019
    Posts:
    72
    Fingers crossed!
     
  4. Lucas-Meijer

    Lucas-Meijer

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    168
    Should be in the next dots release. Let us know how you like it.
     
  5. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    149
    would be awesome if it was out in time for ludum dare
     
  6. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    1,889
    createtheimaginable likes this.
  7. The-Oddler

    The-Oddler

    Joined:
    Nov 26, 2010
    Posts:
    125
    Still not available? Or am I missing something?
     
    OndrejP likes this.
  8. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
  9. The-Oddler

    The-Oddler

    Joined:
    Nov 26, 2010
    Posts:
    125
    Last edited: Nov 20, 2019
    createtheimaginable and siggigg like this.
  10. The-Oddler

    The-Oddler

    Joined:
    Nov 26, 2010
    Posts:
    125
    It is available!
     
    Last edited: Nov 24, 2019
    createtheimaginable likes this.
  11. BanJaxe

    BanJaxe

    Joined:
    Nov 20, 2017
    Posts:
    47
    How does it work? I tried this but I can't see any generated component in the editor.

    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. [GenerateAuthoringComponent]
    4. public struct TestData : IComponentData
    5. {
    6.     public float Value;
    7. }
     
  12. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,603
    Your code works fine for me.

    upload_2019-11-25_9-56-38.png

    upload_2019-11-25_9-56-45.png
     
  13. BanJaxe

    BanJaxe

    Joined:
    Nov 20, 2017
    Posts:
    47
    Strange, nothing comes up for me. Created a new Unity 2019.3.0b12 project, latest Entities package.

    I'll try downloading the 2020 alpha.
     
  14. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,603
    I did this in 2019.3
     
  15. BanJaxe

    BanJaxe

    Joined:
    Nov 20, 2017
    Posts:
    47
    When I go to AddComponent and type TestData or TestDataAuthoring nothing comes up. But if I use the promt to add a new script called "TestDataAuthoring" it does say "A class called TestDataAuthoring already exists", so it is generating it, but for some reason the editor won't display it.
     
  16. BanJaxe

    BanJaxe

    Joined:
    Nov 20, 2017
    Posts:
    47
    Aha I figured it out! It was a very strange interaction with comments.

    My actuall file was like this:

    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. // [GenerateAuthoringComponent]
    4. // public class TempData : IComponentData
    5. // {
    6. //     public int Value;
    7. // }
    8.  
    9. [GenerateAuthoringComponent]
    10. public struct TestData : IComponentData
    11. {
    12.     public float Value;
    13. }
    Once I removed the comment it works. Seems like it was confusing the editor, I assume this is a bug?

    Thanks for the help.
     
    createtheimaginable likes this.
  17. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    283
    class vs struct

    EDIT: AAAH I actually misread the issue. So you had the comment above (still commented) but had it as a struct?

    Iiiinteresting.
     
  18. BanJaxe

    BanJaxe

    Joined:
    Nov 20, 2017
    Posts:
    47
    Yes it was breaking it even when commented out. I've tried putting the comment back and it breaks again.
     
  19. BanJaxe

    BanJaxe

    Joined:
    Nov 20, 2017
    Posts:
    47
    Well seems like I ran into another problem already...

    Adding any generated component to a GameObject with a ConvertToEntity component immediately crashes the editor when entering play mode. Only happens with the generated authoring components.
     
  20. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    71
    [GenerateAuthoringComponent] does unfortunately suffer from the current Unity limitation that we only allow one MonoBehaviour (generated or not) per script file in Unity. This means that you currently can only have one in a file and it needs to not contain any other MonoBehaviours. We hope to fix this in the future.

    @BanJaxe Can you give me any more details on the setup that is causing the crash? Do you get a crash when running the Samples\Assets\HelloCube\1. ForEach\ForEach scene (it uses a generated authoring component)?
     
    armariya and The-Oddler like this.
  21. BanJaxe

    BanJaxe

    Joined:
    Nov 20, 2017
    Posts:
    47
    I can't reproduce the crashing behaviour now. The sample scene works fine.

    It may have been related to the problem with comments. Example:

    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. // [GenerateAuthoringComponent]
    4. // this line breaks everything struct
    5.    
    6. [GenerateAuthoringComponent]
    7. public struct TestData : IComponentData
    8. {
    9.     public float Value;
    10. }
    11.  

    Line 4 breaks the authoring component in the editor. Delete just that comment on line 4 and it works again.
     
  22. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    71
    Good to hear about the sample scene and thanks for the code example. We will have a fix for the commented out attribute issue shortly.
     
    createtheimaginable likes this.
  23. unity_vly97dBKu76VNA

    unity_vly97dBKu76VNA

    Joined:
    Dec 7, 2019
    Posts:
    1
    So it seems like the authoring component generation is using strict string matching rather than going through the C# parser...

    Works:
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Mathematics;
    3.  
    4. [GenerateAuthoringComponent]
    5. public struct Velocity : IComponentData
    6. {
    7.     public float2 Value;
    8. }
    Doesn't work:
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Mathematics;
    3.  
    4. [GenerateAuthoringComponent()]
    5. public struct Velocity : IComponentData
    6. {
    7.     public float2 Value;
    8. }
    Doesn't work:
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Mathematics;
    3.  
    4. [GenerateAuthoringComponent]
    5. public struct Velocity: IComponentData
    6. {
    7.     public float2 Value;
    8. }
     
  24. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    71
    @unity_vly97dBKu76VNA Thanks for bringing that to our attention. We have a fix in for 20.1 (we will try to backport to 19.3 as well).
     
  25. armariya

    armariya

    Joined:
    Aug 22, 2014
    Posts:
    2
    I found out that if I don't have any of my own system in project and I have only components with [GenerateAuthoringComponent], it will crash when hit play button.
     
  26. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    478
    So glad to see this functionality in 0.2.0, thank you!

    Will [GenerateAuthoringComponent] gain support for IBufferElementData at some point in the future? That would be very helpful as well. :)

    I use IBufferElementDatas to represent ai behaviors in my project, and those end up being 90% of what I need to write separate conversion MonoBehaviours for.
     
  27. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,139
    Do you really want to have one array per MonoBehaviour? When would that be useful?

    Maybe better to create a monobehaviour with handwritten conversion...
     
    PublicEnumE likes this.
  28. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    478
    That would be useful, at least in my case - for the same reason that it’s useful for IComponentData. Right now, anytime I’d like to add a DynamicBuffer to an entity in the editor, I need to write a custom conversion MonoBehavior.
     
    Last edited: Dec 14, 2019
  29. SupinePandora43

    SupinePandora43

    Joined:
    May 13, 2019
    Posts:
    18
    I can't add ComponentData to gameobject until my system have errors!!!
     
unityunity