Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

DOTS Change Material within System

Discussion in 'Entity Component System' started by Hobnob93, May 7, 2020.

  1. Hobnob93

    Hobnob93

    Joined:
    May 19, 2017
    Posts:
    5
    Hey, everyone! Long time since I've been on here.

    Been jumping into Unity DOTS - really enjoying it! However, I do have a question that I can't seem to find an answer to.

    Essentially, I have a system which adds a tag to an entity when a given condition is met. I'd like to have another system that picks up entities which have this tag, so the concerning entity's material can be changed (and the tag removed).

    Now, to get the material I know I need to get the RenderMesh, change the material, and then set it back again. What I don't know, is the best way to give the material to the system.

    I could use a Singleton manager class, but seems icky. I could also make the tag an ISharedComponentData and have the material within there, but I'm not too keen on that idea either. Mainly as I'm not sure how the component instance would get that material reference if it's being assigned by another system - it just leads to a Singleton material manager of sorts again.

    As you can tell, I don't like this SIngleton idea. I know it will work, but I'm wondering if there's something better out there. Perhaps an angle I haven't considered, or maybe even something built into Entities that makes this process easier! I know there is an [Inject] attribute for the systems, but not really dived into that as of yet - perhaps that has features that could help me.

    Anyway, I'm rambling. Thank you in advance :D
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  3. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    Hobnob93 and Joe-Censored like this.
  4. Hobnob93

    Hobnob93

    Joined:
    May 19, 2017
    Posts:
    5
    Thank you, Joe-Censored. I'm a bit of a noob to these Forums. For some reason, I incorrectly assumed the tags chosen would put the thread in front of the correct eyes. My apologies! It has since been moved. Will be sure to seek out the correct forum space in future :)
     
  5. Hobnob93

    Hobnob93

    Joined:
    May 19, 2017
    Posts:
    5
    Ahh, this is perfect! I've not really dabbled into the Render Pipeline much, yet. Sounds like a good time to be getting involved with it. Much appreciated!
     
  6. Krooq

    Krooq

    Joined:
    Jan 30, 2013
    Posts:
    196
    Did you figure out how to do this in code? I'm really struggling to find the docs for the API
     
    LogicProjects likes this.