How do I export Node2D (packed scene) that has its own export variable?

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

I have an Enemy scene, however I want to change attack for some instances. Attack is a scene, where you can change number of bullets, speed and ect and it is a part of an enemy node, here is a visualisation:
Enemy
|-State Machine
||-Some states
||-Attack
|||-Pattern

I know that you can make editable children when instancing, but perhaps there is another way

:bust_in_silhouette: Reply From: aXu_AP

If you don’t want to edit children directly then you need to tell Enemy to change it’s children’s parameters. That means you need to have export variables on Enemy’s script and some logic to relay these parameters further down to Attack. It’s not hard, but of it does add a bit extra code for each parameter you want to change, and couples Enemy’s and Attack’s code more tightly, which is usually undesired.

However, there’s 2 more options if you are willing to change things around a bit:

  1. You can remove the Attack from Enemy’s scene, and add it by hand to every instanced enemy. This should work out of the box, however you lose default behaviour.

  2. Make Attack a custom resource and export that. In this case, Attack will not be it’s own scene, so I don’t know if it’s a viable alternative for your use case. But if Attack is there mainly to collect some parameters together and maybe have some custom function, this is nice way. You can also define default behaviour. One minus comes from Godot 3’s lacking custom resource editor support (4 will support these fully). It doesn’t hinder any potential of this system, but usability does suffer a bit.