Page 1 of 1

How can I access data in Monobehaviour?

PostPosted: Sat Dec 01, 2018 5:40 pm
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

Re: How can I access data in Monobehaviour?

PostPosted: Sat Dec 01, 2018 5:59 pm
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!