0 votes

I'm trying to find an example of how to exactly use the _make_custom_tooltip() method? Can anyone share what I'm doing wrong?

Documentation:
Godot Documentation _make_custom_tooltip()

-

I currently have something like this:

# 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.

Godot version v3.3.3-stable
in Engine by (164 points)

1 Answer

+1 vote
Best answer

This

func _ready():
    num_castles_icon._make_custom_tooltip("Total Castles")

is redundant

by (1,438 points)
selected by

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?

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.

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.

Thank you!

You can automate script attachment.

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.