Search Unity

How to associate resource files to an entity?

Discussion in 'Entity Component System' started by Exeneva, Dec 10, 2018.

  1. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    Hi, I'm new to ECS and have a basic question.

    I have a Material in my project that I'd like to apply to a MeshInstanceRendererComponent on one of my entities (I have a reference to this entity already)

    In normal Unity I would just drag and drop in the inspector or use Resources.Load()

    How would I do this? Is there a recommended workflow for ECS?
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    It is rather convoluted but you can make a SharedComponentDataWrapper in your scene with Material field then you could drag and drop. This makes a new entity holding that material. ECS system then try to get that entity containing the drag and dropped Material and assign to MIRs.
     
  3. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    Can you give an example?
     
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    AComponent.cs

    [Serializable]
    public struct A : ISharedComponentData { public Material m; }
    public class AComponent : SharedComponentDataWrapper<A> { }

    Attach to GO, drag drop, then in system

    var cg = GetComponentGroup(typeof(A))
    Material mat = cg.GetSharedComponentDataArray<A>()[0].m;
     
  5. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    Is there really no other way? What if I have tons of objects in my scene? Seems like quite a hack without the ease of use the editor provides since I'd need to make a large Material array ordered by index (instead of name or reference to an entity).

    Is this one of the limitations of Pure ECS? Is Pure ECS even possible with custom Materials in the game?
     
    Last edited: Dec 10, 2018
  6. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
  7. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    That looks awesome. But I don't see Addressable Assets in 2018.2.19f1?
    upload_2018-12-10_1-10-8.png
     
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    You must add Addressables in to manifest manually, first time.
     
    Exeneva likes this.
  9. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    What's the entry / version to add? Copy/paste from your manifest?
     
  10. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Look at:
     
    Exeneva likes this.