SetMaterial action use wrong material in some cases. It depends on how materials named.

* Reproduce 100% if scene data is so

* You can see at wrld_2d141628-bab5-461d-b0ff-7c81e1a0ebb0

* Tested with client 2018.3.2 built636, SDK VRCSDK-2018.10.02.10.29_Public

REPRODUCE STEPS:

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

1. Create new world (Create new project, make floor, add VRC_SceneDescriptor, assign Spawns point).

2. Create materials

2-1. Create two materials in diffrent folder.

2-2. Name these equal name. (Ex. "f1/Mat.mat", "f2/Mat.mat")

2-3. Change albedo color as visually identifiable. (Ex. Red to "f1/Mat.mat", Blue to "f2/Mat.mat")

2-4. Create two objects and assign each materials. (This step is for ensuring materials available in DynamicMaterials of VRC_SceneDescriptor. I used spheres in following screenshot.)

3. Setup SetMatrial action

3-1. Create two objects. Name t1 and t2. (I used cubes in screenshots.)

3-2. Setup VRC_Trigger > OnInteract > SetMatrial to self. And use each created material for material parameter of the action

4. Test

Expected behaviour:

Interaction with t1 changes t1 material to "f1/Mat.mat". And,

Interaction with t2 changes t2 material to "f2/Mat.mat".

Actual result:

t1 and t2 change to identical material.

5. Additional test

5-1. Change material name of that is not appeared actually in privious test. Add characters to the tail of original name. (ex. "Mat111.mat")

5-2. Setup VRC_Trigger again. (This step need because VRC_Trigger doesn't follow material renaming.)

5-3. Test. The result doen't change.

This means equal name is not true source of this issue.

(If it is not reproduced. Try exchange materials name. It depends on reordering DynamicMaterials when SDK builds world. I couldn't get ordering rule enabling 100% reproduce.)

MY ANALYSIS:

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

I guess the runtime behavior of Set Material action as follows:

1. Extract parameter string from SetMaterial action. Check it begins with "Assets/". If so, continue.

2. Remove charcters from beginning to last "/" .

3. Iterate DynamicMaterials of VRC_SceneDescriptor from head, and check if its material name (not include path and ".mat" extension) matches head of the string of step 2. If it matches, use that material.

I think it should also use folder names section of specified asset path string.

And of course, it should compare entire string.

SCREENSHOTS AND LOG:

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

This is result of additional test.

1. f1/Mat.mat is actually red.

2. f2/Mat111.mat is actually bule.

3. Both SetMaterial use f1/Mat.mat

Triggers actually use f1/Mat.mat and f2/Mat111.mat.

> 2018.10.03 12:19:54 Log - [VRC_TriggerInternal] 15.12996 t1 via OnInteract executing [SetMaterial (False, 0.000, 0, "t1", Assets/iwsd_vrc/Issues/set-material-to-unexpected/Reproset/f1/Mat.mat, 0)]

> 2018.10.03 12:19:55 Log - [VRC_TriggerInternal] 15.6973 t2 via OnInteract executing [SetMaterial (False, 0.000, 0, "t2", Assets/iwsd_vrc/Issues/set-material-to-unexpected/Reproset/f2/Mat111.mat, 0)]

(Recently we had software version up. So this screenshots aren't taken with latest software. But I could reproduce with latest. It's same.)

WORKAROUND

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

Name materials uniquely with long name. Don't use a name which matches the head of another material name.

ABSTRACT IN JAPANESE

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

概要

SetMaterial アクションが間違ったマテリアルを使う事がある。起こるかどうかはマテリアルの名前の付け方に依存している。

マテリアル選択のアルゴリズムはおそらく次のようになっている。

1. SetMaterial の文字列を取り出す。先頭が「Assets/」であることを確認する

2. 文字列の先頭から最後の「/」までを捨てる

3. DynamicMaterials を先頭から見ていき、そのアセットの名前(パスと「.mat」は含まれない)が前述文字列の先頭部分に一致したら、それを使用する。

これにより同名のマテリアルが別のフォルダに入っているとどちらか一方しか使う事が出来ない。そうでない方を使っている SetMaterial は間違ったマテリアルを使用することになる。

この現象を起こすのに名前は完全に同じである必要は無く、使われる方のマテリアルの名前と先頭部分でさえあれば良い。