How can I create unique instance of Scene using script?

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

I want to instance a scene and show it before each level in my game. So I use the instance method like -

var MyScene = load("res://Scenes/MyScene.tscn")
var myScene = MyScene.instance()

Now this works, but there is a problem. If I run any script on this scene to say modify size of text, this modification persists when I create another instance of this scene.

Even though when the second instance is being made, the first instance is freed, the second instance contains modification made on first instance (through script).

I want to have unique instances of the scene, which do not share modifications.

Size of which text?
That Scene will contain other Ressources which may be shared between instances. You might need to make the specific ressource which you are altering unique.

wombatstampede | 2019-10-18 11:16

@wombatstampede: I have made the resources unique already. That’s not the problem. I’d like to change the size of same text in different instances of the scene. But looks like that is not possible right now in godot.

Vinayak Garg | 2019-10-20 14:30

Maybe it is best when you share the part of code where you change the font size.

Do you create a new Instance of DynamicFont or BitmapFont and then use add_font_override() of the label?

wombatstampede | 2019-10-21 16:10

:bust_in_silhouette: Reply From: BerndVP

Resources migth be shared between instances of a scene i think. So you should try to create a new resource or make the resource “local to scene”.

But for the text this should not be the case…