Problem with setting a shader material into a group

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

Hi everyone!

I create a UI for my game and would like that some buttons have a blue outline stroke when during a hover.

For this, I made a shader and added the set of buttons into the group “hasBlueStroke”. Next, I wrote this code in my script which rules the UI:

func _connect_blue_outline_shader():
	var nodesHasOutlineStroke = get_tree().get_nodes_in_group("hasBlueStroke");
	for node in nodesHasOutlineStroke:
		node.connect("mouse_entered", self, "_set_outline_shader_material");
		node.connect("mouse_exited", self, "_reset_outline_shader_material");
		pass
	pass

func _set_outline_shader_material():
	self.material = outlineShaderMaterial;
	pass

func _reset_outline_shader_material():
	self.material = null;
	pass

Resource of “outlineShaderMaterial” added at the title of script like onready.

I see that this resource and script work correctly in the debugger. I mean the resource is right and actions with mouse_entered and mouse_exited work well. But in run time the outline stroke is not displayed.

At the same time, if I assign material to each button separately, everything works great.

Earlier I wrote a similar code for connecting sounds to buttons. It is in the same script that governs the interface and works very well:

	var nodesNeedButtonHoverRing = get_tree().get_nodes_in_group("hasRingingSoundHover");
for node in nodesNeedButtonHoverRing:
	if !node.is_connected("mouse_entered", self, "play_button_hover_ring"):
		node.connect("mouse_entered", self, "play_button_hover_ring")	
		
pass

Any ideas?

I’m new in Godot and would appreciate any help. Have a nice day, everyone!

:bust_in_silhouette: Reply From: SnapCracklins

Weird question: have you done anything to normalize your mouse input? I ask because i notice the function that is working is the one with “mouse_entered” only and not both the enter and exit. The code, as you said, is fine.

I frequently read stories about people having trouble with jiggly graphics (shifting position) when they plot mouse movements to an object. I had the same thing happen with my mini-game i am working on when i tried a line of code that was suggested somewhere.

Try adding a code to handle mouse input. I don’t know if you are using a cursor object or anything but try adding something like:

var mouse_position = Vector2(0,0) #or screen center
Self.position.x = get_global_mouse_position.x
Self.position.y = get_global_mouse_position.y

Bouncing back and forth may be interfering with your enter and exit signals? Just a guess.