Forum rules - please read before posting.

Object: Change material, material index issue and/or confusion

The object I want to change material on has several materials (Several elements in unity) and changing the "0" material using Object: Change material always works, but when I try setting the second material (index 1 instead of 0), nothing changes. Have I misunderstood how this works? Does the material index refer to something other than the list of elements under "materials" in unity?

I'm on Unity 2020.3.0f1 using the HD RP and currently on AC 1.73.2

Comments

  • No, that is how it should work. Is the material updating in the Inspector?

    It may be due to the way HDRP works. Try opening up ActionChangeMaterial.cs, and replace the two instances of:

    .materials
    

    with:

    .sharedMaterials
    

    Does that have any effect?

  • No effect whatsoever, unfortunately.

    The inspector is consistent with what I see in-game, the material of index 1 has not changed.

  • Can you share screens of the full Inspector, as well as the Action?

  • I solved the mystery!

    Object: Change material works just fine on all elements. What does not work however, is correctly copying a "Object: Change material" action. When I copied my action and changed index, I assumed it had kept the reference to the renderer. It had, however, swapped it for another renderer with the exact same name. Just a completely different one. So it looked right just looking at the action, but upon closer inspection I noticed it was now referencing a completely different object.

    (They're both based on the same mesh, so it was a good guess, albeit an incorrect one.)

    Let me know if this wasn't clear enough.

    Either way the problem is solved for me, I'll just manually make sure they're referencing the right renderers.

    Thanks for your time!

    t

  • As in, two different GameObjects with the same name? Was this from a scene-based ActionList?

    Sounds odd. Scene-based Actions rely on Unity's own ObjectField method to store object references, so it may be more of a Unity issue.

    I'm not sure there's much that can be done in that event, but I appreciate the follow-up.

  • Two different game objects that do not have the same name, but one of their child renderers has the same name as that of a separate game object. And both these objects are based off of the same mesh. Sounds like a unity reference issue indeed.

    It's not really a problem now that I'm aware of it. :smile:

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.