0 votes

So, we can do:

export(AudioStreamSample) var Music_Stinger
export(bool) var Trigger_On_Enter

How can I export a CollisionPolygon2D? I have a area2d node saved, which has a child CollisionPolygon2D, it is a trigger for musics and stingers in the game, however, I would like to know if it's possible to expose in the inspector a CollisionPolygon2D similarly like the above, so I could customize a collision shape for the map,

in Engine by (360 points)

1 Answer

0 votes

You can save the CollisionPolygon2D node as a scene, and then export a var like this:

export(String, FILE, "*.tscn") var my_collision_polygon_scene

func _ready():
    add_child(load(my_collision_polygon_scene).instance())

If the collision polygon node is already in the scene tree for some reason, you can export a NodePath and duplicate the node:

export(NodePath) var my_collision_polygon_node_path

func _ready():
    add_child(get_node(my_collision_polygon_node_path).duplicate())
by (1,088 points)
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.