I can't figure out how to get/set if a material has emission enabled

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By clambu

Hi all!

I’m new with Godot.

I’m trying to select the enemy which I want to attack with mouse on a 3D environment. This consist on “glowing” the enemy when mouse_enters/exits and Second, would be to put a small circle under the player if it is selected.

For “glowing” the enemy I would like to get if the material has emission_enabled. According to the documentation[1] I have:

bool emission_enabled
Setter 	set_feature(value)
Getter 	get_feature()

So I’m trying the following:

thisMaterial=get_node("MeshInstance").get_surface_material(0)
print(thisMaterial.get_feature(emssion_enabled))

but it doesn’t work, and haven’t been able to figure out how to get/set it. Can someone give me some clues how to use it ?

I came with a solution where I store all the object materials to an array when _ready, then load an specific material when mouse enters, and restore the stored materials when mouse exits., being able to change emission_enabled and the emission level would give me a much more efficient way to proceed.

Thank you very much in advance.

[1] http://docs.godotengine.org/en/latest/classes/class_spatialmaterial.html#class-spatialmaterial

:bust_in_silhouette: Reply From: SIsilicon

I don’t know about you, but I’d just skip using the get/set functions entirely and just do this.

emit = emission_enabled #get emission
emission_enabled = emit #set emission

So your code would look like this.

thisMaterial=get_node("MeshInstance").get_surface_material(0)
print(thisMaterial.emission_enabled)

Thank you for your answer, but I could not make your example work. Finally I came with this solution:

	thisMaterial=get_node("MeshInstance").get_surface_material(i)

    # 1 correspond to FEATURE_EMISSION as per docuementation
	thisMaterial.set_feature(1,true)
	thisMaterial.set_emission_energy(3.0) 

but for some reason the CPU spikes on the profile, so I will be using my previous code for the moment

clambu | 2018-10-16 15:10

:bust_in_silhouette: Reply From: dirkk0

This works in Godot 3.2.4b4:

var tween = $Tween
var mat = my_node.get_surface_material(0)
tween.interpolate_property(mat, "emission_energy", 0, 1, 1, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start()

Additionally, you can also twek these parameters:

mat.emission_enabled = true
mat.emission_energy = 0.5