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. Dismiss Notice

Question How can I get a managed ISharedComponentData ?

Discussion in 'Entity Component System' started by Dog_Like, May 4, 2023.

  1. Dog_Like

    Dog_Like

    Joined:
    Nov 24, 2017
    Posts:
    25
    Code (CSharp):
    1. public struct Shared : ISharedComponentData, IEquatable<Shared>
    2. {
    3.     public GameObject go;
    4.  
    5.     public bool Equals(Shared other)
    6.     {
    7.         return other.go == go;
    8.     }
    9.  
    10.     public override int GetHashCode()
    11.     {
    12.         return 0;
    13.     }
    14. }

    How can I get an ISharedComponentData like this in an ISystem? I tried using SystemAPI.GetSharedComponentTypeHandle, but it only works with unmanaged data.
     
  2. RichyHuang

    RichyHuang

    Joined:
    Aug 24, 2020
    Posts:
    10
    EntityManager.GetSharedComponentData
     
    Dog_Like likes this.
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
  4. DatCong

    DatCong

    Joined:
    Nov 5, 2020
    Posts:
    77
    u should juse class in steal of struct
     
    Dog_Like likes this.