How to assign a custom scene to an exported variable in Godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Diet Estus

I have a BossTrigger node that I’m using to trigger introductory animations in my Boss nodes. The trigger is essentially just an Area2D. In my boss room, I want to place a BossTrigger and associate that trigger with a Boss that is also in that room.

Currently, in my BossTrigger script, I have

export(NodePath) var associated_boss

I then manually assign my boss to the trigger in the editor.

Unfortunately, when my player enters the trigger and my on_trigger_entered() function is called, I’m getting an error that there’s no index ‘animation_player’ on base ‘NodePath’. I’m certain my boss has an variable called animation_player, so I’m not sure what the issue could be.

Any ideas?

:bust_in_silhouette: Reply From: paolobb4

Hey, well NodePath is just a path to the node, is meant to be used with get_node().
I’d say try using export(Node) var associated_boss instead… that or some other type, not sure.
You could always use get_node() if it doesn’t work but it should.

You can’t use Node as export argument.

Oen44 | 2018-09-20 20:26

:bust_in_silhouette: Reply From: Oen44

If you are exporting NodePath then you have to use that as argument for get_node

export(NodePath) var associated_boss
var boss = get_node(associated_boss)
boss.animation_player

It’s obvious in hindsight. Thanks!

Diet Estus | 2018-09-20 23:48

This was very helpful to me–thank you so much!

RaebaldKashban | 2021-11-27 16:22