How to remove/add material tag at runtime?



Hand tag is for always visible on screen.

i am using a material tag called “hand” to render a mesh always on top of everything. this works fine for my player hand because it renders in a separate top render pass.

the problem starts when i pick up objects. some of those objects use normal “model” materials so they render in the opaque pass instead of the hand pass. because of that the hand mesh clips through them or parts disappear depending on depth.

i already made a previous post about another issue and got some suggestions but i have not tested them yet. before trying everything i want to understand the correct approach. How to Disable a Script in Defold Without Removing Other Components - #7 by Mathias

should i:

create a dedicated template gameobject that always uses a fixed hand material and dynamically load meshes into it when the player holds something (which is suggested in the post)

or

is there a clean way to switch material tags at runtime so an object can move between normal rendering and hand rendering without duplicating setups

1 Like

I think you can change material at runtime (see API but it is a property I guess), but it seems there is a problem if you have multiple textures in the material or multiple material in same model see

I think you should not overthink that and just try the solution that seems more appropriate or easy for you. If you already have all your scripted object you dont want to touch, it will be easier to add a template gameobject and just add some items data to handle everything.

If you already have some state machine in your scripted objects, it could be easier to add a state and change material in while in this state.

You know the good choice

1 Like