godotengine / godotengine/godot-docs

GDScript initialization order for scene instances clarifications

Open
#11,154 0 comments 0 reactions 0 assignees View on GitHub
area:manual topic:gdscript
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**Your Godot version:**

v4.5.beta.custom_build [2d113cc22]

**Issue description:**

In the GDScript docs for [initialization order](https://docs.godotengine.org/en/4.4/tutorials/scripting/gdscript/gdscript_basics.html#initialization-order), it briefly mentions that exported variables are applied after `_init` for instantiated scenes.

However, it is not clear that this also applies to the script field itself. This causes the original script's `_init` to be called first, then the new script to be applied, then its `_init` being called, which [appears like a bug](https://github.com/godotengine/godot/issues/106933).

In addition, this means you should be very cautious using exported variables in `_init`, since if that script is ever used in an instantiated scene, the values will not reflect the overridden values.

**URL to the documentation page (if already existing):**

https://docs.godotengine.org/en/4.4/tutorials/scripting/gdscript/gdscript_basics.html#initialization-order

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.