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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question How to add an Aspect to an Entity

Discussion in 'Entity Component System' started by deshalb, Mar 1, 2023.

  1. deshalb

    deshalb

    Joined:
    Feb 22, 2013
    Posts:
    12
    Hey, im looking into Aspects for the first time, but i can not get any of my Aspects to show up in the Inspector.
    (Unity 2022.2.7f1, Entities 1.0.0-pre.44)

    e.g. if i create a simple example-aspect

    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Transforms;
    3.  
    4. public readonly partial struct TestAspect : IAspect
    5. {
    6.     readonly RefRO<LocalTransform> tr;
    7. }
    i woul expect basically every Entitie (all my Entities have Local Transforms) to have this Aspect. But only the TransformAspect (and for Entities with Colliders the ColliderAspect) show up in the Inspector.
    Do i have to do something special, to add an Aspect? What am i missing?

    Thanks for help in advance!
     
  2. Naewulf

    Naewulf

    Joined:
    Jun 17, 2019
    Posts:
    23
    I don't know if this is a bug. Had the same issue, and every time I tried to check out if my aspect was showing in the Aspects list my unity editor ended up crashing a little while later. I think it's probably something that will be fixed in the near future (I hope).
     
  3. deshalb

    deshalb

    Joined:
    Feb 22, 2013
    Posts:
    12
    Thanks for your answer. I also thought it might be a Bug. Maybe someone had the same issue and can share a workaround or a unity and ecs Version combination that should work?
     
    Last edited: Mar 1, 2023
  4. deshalb

    deshalb

    Joined:
    Feb 22, 2013
    Posts:
    12
    I found a solution / the missing part in my code:

    The Aspect must be in a namespace like this:
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Transforms;
    3.  
    4. namespace MP.normal
    5. {
    6.     public readonly partial struct TestAspect : IAspect
    7.     {
    8.         readonly RefRO<LocalTransform> tr;
    9.     }
    10.  
    11. }
    I put all my Scripts in a namespace, and now the Aspects apear.
     
    linh60bpm and Naewulf like this.
  5. Naewulf

    Naewulf

    Joined:
    Jun 17, 2019
    Posts:
    23
    Thanks for the info. Im also gonna try that, since I am not using namespaces just like you.
     
  6. Quit

    Quit

    Joined:
    Mar 5, 2013
    Posts:
    63
    That's a bug surely. Depends if Unity fix it though.
     
  7. linh60bpm

    linh60bpm

    Joined:
    Oct 13, 2018
    Posts:
    8
    this fixes my error.