Trying to setup a button so that it is hidden at first, shows up when the mouse hovers over it, then disappears again when the mouse moves away. Here’s my code:
‘’’
using Godot;
using System;
public partial class draw : Button
{
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
Visible = false;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void OnMouseEntered()
{
Visible = true;
}
private void OnMouseExited()
{
Visible = false;
}
}
‘’’
I’ve been able to confirm that the signals are connected because if I make the button visible to start with I can make it disappear through setting that value in either signal method, but I can’t make it visible again. Do these functions just not work on a hidden object? If so, is there a setting to make it so they do?
It seems that mouse entered/exited signals aren’t emitted when the control is hidden. Try replacing Visible = true and Visible = false with Modulate.A = 1f and Modulate.A = 0f.
fyi c# has extension methods. you can use an extension method to change A without needing to: new Color(Modulate.R, Modulate.G, Modulate.B, value) It doesn’t really matter, but now you know.
public static class GodotColorExtensionMethod {
public static Color SetAlpha(this Color a_color, float a_alpha) {
return new Color(a_color.R, a_color.G, a_color.B, a_alpha);
}
}
public partial class Button:Godot.Button {
public override void _Ready() {
SelfModulate = SelfModulate.SetAlpha(.5f);
GD.Print(SelfModulate);
}
}