+3 votes

Is there a way to specify the type of a NodePath?

Say I have export(NodePath) var target, is there a way I can specify target should be a KinematicBody, Target.gd, etc.?

in Engine by (91 points)

2 Answers

+4 votes
Best answer

No, there is no way to filter by class.

If you need a restriction to avoid mistakes you can make a setter that checks, prints an error and ignore nodes of the incorrect type.

by (7,898 points)
selected by
0 votes

from https://godotengine.org/qa/123057 (Mine)

You can do this by using _get_property_list()

func _get_property_list() -> Array:
    return [

At hint=35 is not in the docs; I found it from here

I have no idea how to do it for export key-word, though. Trying

export(NodePath, 'Node') var test: NodePath

return an error
Parse Error: Type "NodePath" can't take hints.
Advance export docs

by (79 points)
edited 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 Frequently asked questions and 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.