How can I access data in Monobehaviour?

Node-based Shader Editor
Post Reply
Zenneth
Posts: 1
Joined: Sat Dec 01, 2018 5:27 pm

How can I access data in Monobehaviour?

Post by Zenneth »

Here's the specific Scenario.

Each of our Game character will have an enum TEAM that designated which TEAM it is on.

TEAM1 to TEAM4 each has specific Color assigned to them.
And they got multiplied on to the base Texture.

TEAM1 => Red
TEAM2 => Blue
TEAM3 => Green
TEAM4 => Yellow

Currently, we have one Material per Team,
which is really redundant and cost ineffective, considering that everything else are all identical.

So, we want the shader to be able to access that data, and automatically choose the color via a switch.

Also, because Vertex Color are needed for other purposes, they cannot be used in our case.

-------------------

Could anyone help us in solving this ?

THX in advance
User avatar
Ricardo Teixeira
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: How can I access data in Monobehaviour?

Post by Ricardo Teixeira »

Zenneth wrote:Here's the specific Scenario.

Each of our Game character will have an enum TEAM that designated which TEAM it is on.

TEAM1 to TEAM4 each has specific Color assigned to them.
And they got multiplied on to the base Texture.

TEAM1 => Red
TEAM2 => Blue
TEAM3 => Green
TEAM4 => Yellow

Currently, we have one Material per Team,
which is really redundant and cost ineffective, considering that everything else are all identical.

So, we want the shader to be able to access that data, and automatically choose the color via a switch.

Also, because Vertex Color are needed for other purposes, they cannot be used in our case.

-------------------

Could anyone help us in solving this ?

THX in advance
Hey there,

You can't arbitrarily access information from a shader but you can pass information directly to it, check the Smear sample for a specific example on how to achieve it.

However, changes made to a shader affect all materials using it, I recommend adjusting a Material Property instead which is unique per-material.

Be sure to let us know if you have any followup questions.

Thanks!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
Post Reply