+2 votes

I'd like to change material of CSGMesh in my game from within a script.

How can I do this from GDscript?

I have tscn with root of CSGMesh, and the Mesh property is a tres file.
I spawn this tscn multiple time and when I click on one of the tscn I want it to change material to premade Material and delete it when the click is released.
In the past I used Area(with MeshInstance named Mesh) for this and changed the material via:

extends Area
...
$Mesh.material_override = load("res://materials/lowpoly_half.material")

but the CSGMesh didn't seem to have the material_override property,
and if I'm using this:

extends CSGMesh
...
mesh.surface_set_material(1, load("res://materials/lowpoly_half.material"))

every instance of the tscn change it's material.

in Engine by (14 points)

Please log in or register to answer this question.

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.