0 votes

According to Godot Docs, I can use it to cast arguments or other objects to the type I desire. Afterward, I can even drag the object output to get full completion:

enter image description here

And it is also possible to cast to a script, which will allow complete script properties and functions:

enter image description here

However, I can't understand it at all, I am new to Godot. Can someone please explain some examples use cases of this node? Thanks.

in Engine by (31 points)

1 Answer

+1 vote
Best answer

Although this is an old question, I found it while trying to find how to specify the base type to cast to, so I'll answer the original question as well.

Suppose you have a node that emits an "input_event" signal. This signal will give you a base InputEvent but that doesn't tell you what kind of input you just received. Maybe the mouse was moved or there was a click or the user entered a keyboard input. By trying to cast that input event to the InputEventMouseButton type, you can test whether the input was a mouse button input and run your code only in that case instead of on all types of input events.

Another case where you might want to cast is if you want to call a function with an argument that you don't quite have the right type for but you have something that can be cast into the right type. For example, you can safely cast an integer to a float because it effectively just means adding a decimal point and zero on the end of your integer. Now if you had a function that needed a float instead of an integer, you have your float.

by (46 points)
selected by
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.