+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.

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

asked Apr 11, 2016 in Engine by unfa (179 points)

1 Answer

+1 vote

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)

answered Apr 11, 2016 by rgrams (526 points)
edited Sep 25, 2016 by rgrams

Link offline.

Thanks, fixed.

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

extends MeshInstance

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

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)
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.