godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.98k stars 21.16k forks source link

Editor meta overwrites meta values set inside _init() #36871

Closed KoBeWi closed 2 weeks ago

KoBeWi commented 4 years ago

Godot version: 3.2

Issue description: When you try to set a value in a node inside it's _init() call, it will be immediately overwritten with editor-specific values, like __edit_lock. I mean the meta dictionary is replaced, so your values are lost.

Instance.tscn

func _init() -> void:
    set_meta("test_meta", true)
    print(has_meta("test_meta")) #true

Main scene

func _ready() -> void:
    var instance = load("res://Instance.tscn").instance()
    print(">> ", instance.has_meta("test_meta")) #should be true, but it's false if the Instance.tscn is locked in the editor

I know this might be working correctly, but IMO the meta you set and the meta set by the engine should get merged instead of replacing one another.

Minimal reproduction project: ReproductionProject.zip

filsd commented 2 years ago

I can confirm the issue here. Its happening in my current project: I'm using "meta" just to check the type of object and thought of putting it on _init() was a good choice since I needed to know the "obj type" as soon as possible.

KoBeWi commented 2 weeks ago

Fixed, likely after metadata rework.