How to search a Label for a specific word and its position in space?

Godot Version

Godot 4.7

Question

I am making a Papers, Please inspired game where you read documents and approve them is disapprove them based on specific words or symbols. I want to have the words be highlighted on the document, and the player is scored based on if they found and highlighted all the necessary words/symbols.

Ideally, I would let the player freehand highlight. I think that’s more fun than simply clicking the word to highlight it.

Example document:

Name: Example, Author
Date: XX/XX/XX
Department: Example Department

This is an example document. It contains an unapproved word.
(Imagine there is about a paragraph of filler text.)

How would I find the word “unapproved” in this space? I was thinking if I can find it’s coordinates, I could create an Area2D and use the “mouse_entered” signal to have a simple way of knowing the player highlighted the word.

One solution would be to hand make all of the documents, but I hope there is a less time consuming option where I could create a template, and only have to come up with the contents of the document, and not have to have 100 scenes with manually placed Area2D’s on them.

Any help is super appreciated. Thanks!

Label has Label.get_character_bounds() which you may use to build the collision shapes.

If you want to have more control over it then you’ll need to use a lower level API. Check this answer for an overview: