0 votes

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

Godot version 3
in Engine by (15 points)

1 Answer

+1 vote
Best answer

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.

by (1,100 points)
selected 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 [email protected] with your username.