DOTS Change Material within System

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 :smile:

Probably not going to get many responses in the General Discussion forum for a preview feature, since most people are waiting until it settles down before starting a serious project with it. I’d try the DOTS forum for this kind of question.

I think the Hybrid Renderer V2 can do this for both URP and HDRP, but I’ve just gotten everything upgraded to 2020.1 and updated the packages, so I’ve not had a chance to mess with it:

Property overrides: DOTS Hybrid Renderer | Hybrid Renderer | 0.4.2-preview.16
Custom properties: DOTS Hybrid Renderer | Hybrid Renderer | 0.4.2-preview.16

2 Likes

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 :slight_smile:

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!

Did you figure out how to do this in code? I’m really struggling to find the docs for the API

1 Like