Godot plugin to easily add node references to scripts and copy the variable name to your clipboard.
onready var _animated_sprite: AnimatedSprite = $AnimatedSprite
Check out the video tutorial.
- Select one or more nodes. There will be a dropdown menu in the scene toolbar if the plugin detects that one of the node's parents has a script. The plugin will scan recursively up the tree.
- Select the parent to which you want to add the reference.
- Select the last option to copy the last created reference's variable name.
- Reload the parent script by closing it and reopening it. For some reason I can't get it to reload automatically.
- Now you can use that variable.
- Add a reference for a node to one of its parents' script.
- Add references for multiple nodes at once.
- Copy the name of the last made reference.
- Makes sure the reference has the appropriate class. Works with custom
class_name
s andextends
. - Prevents duplicate references.
- Enumerates variable names when there is a conflict in naming.
- Sorts references alphabetically.
The plugin will take the name of the node, convert it to snake case and put a _
in front to show it's a private value.
AnimatedSprite -> _animated_sprite
This plugin will create a code block within the parent script to group all its references. This block looks like this:
### Automatic References Start ###
onready var _animated_sprite: AnimatedSprite = $AnimatedSprite
onready var _kinematic_body_2d: KinematicBody2D = $KinematicBody2D
onready var _ray_cast_2d: RayCast2D = $AnimatedSprite/RayCast2D
### Automatic References Stop ###
You can rename variables, to prevent duplicate references the plugin looks at the path.
You can change the location of this block of code. As long as the ### Automatic References Start ###
and ### Automatic References Stop ###
are unchanged.
Yes, as long as it has the same structure.
Yes, rename away!
You can do one of two things:
- Remove the reference from the reference code block and add it again using the plugin.
- Manually alter the path in the reference code block.
Because NodePaths
bug out some times, in my experience.
The script gets saved to disk correctly, but Godot holds a cache that only get invalidated after closing it. If you know a workaround please let me know.