# This find the correct TextureRect node
onready var num_castles_icon:TextureRect = self.find_node("NumCastlesIcon")
func _ready():
num_castles_icon._make_custom_tooltip("Total Castles")
func _make_custom_tooltip(text:String)->Control:
# This exists, and is a Control node, with a panel-container and label inside of it
var tooltip = preload("res://scenes/ui/ToolTip.tscn").instance()
tooltip.get_node("Label").text = text
return tooltip
The error I get is:
Invalid call. Nonexistent fuction ‘_make_custom_tooltip’ in base ‘TextureRect’.
What’s weird is that a TextureRect does have a hint_tooltip, so I figure I could override the default tooltip with my own as per the documentation.
Any help or direction of where to look further would be much appreciated.
Hmm, well if I remove that, it doesn’t make a difference.
Also, if I don’t have that, where would I enter the tooltip text?
eod | 2021-08-26 22:50
Hmm, well if I remove that, it doesn’t make a difference.
It does: if you remove it, you’ll get rid of memory leak (what’s currently happening).
Just to be clear: you should not call virtual functions by yourself (in most cases). They are called by engine automatically. Specifically, _make_custom_tooltip is called when mouse hovered over Control and hint_tooltip is not empty: you provide your own gui element instance (tooltip in your case) which is displayed and disposed automatically. The later will not happen if you call it manually.
And lastly, of course, this script should be attached to a 'Control` you want to be displaying your custom hint.
sash-rc | 2021-08-27 09:10
And lastly, of course, this script should be attached to a 'Control` you want to be displaying your custom hint.
Ah-ha! That’s what I was missing. I was trying to reference the Control from a parent and then assign a custom tool tip to the Control from there (the parent script). I didn’t realized I need to attach a script to every single button (the Control itself) and add the custom function to it.