+2 votes

The problem is as follows:

I have a few objects that are using the same material. I want each to have different color (texture modulated by an RGB value) and different opacity.

There's a "Modulate color" value in a Sprite3D node that allows to make per-object changes regardless of the material, but this doesn't work if I use a non-standard material.

TL;DR;
How do I modify objects' color and alpha without changing the look of all other objects using the same material?

in Engine by (199 points)

1 Answer

+2 votes

See the answers to my question here: http://godotengine.org/qa/2866/how-do-i-make-material-shader-instances-2d (assuming the same thing works for 3D)

by (532 points)
edited by

Link offline.

Thanks, fixed.

Looks like it doesn't work for 3D...

extends MeshInstance

func _ready():
    var mat = get_material().duplicate(true)
    set_material(mat)

This fails with the following error:

Invalid call. Nonexistent function 'get_material' in base 'MeshInstance (Flare.gd)'.

Adding mesh fixes this issue:

extends MeshInstance

func _ready():
    var mat = mesh.get_material().duplicate(true)
    mesh.set_material(mat)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.