|Topic was automatically imported from the old Question2Answer platform.
I am loading BulletFactory.tscn via autoload singleton.
I don’t understand why its instancing all the objects contained in the scene in autoload. it instances by itself and then I’ve got one of every bullet which are instanced, run physics, etc, which is not the behavior I want.
How do I load it globally without it instancing?
A scene file is loaded as a
PackedSceneclass instance, which inrehits
Resource class. When a scene is instanced, any child nodes will be instanced together.
You need to remove any node from an autoload scene if you don’t want them to be instanced upon game starting.
Too achieve what you want, you can save all your bullet node as scene files. And use
var bullet_scene :PackedScene = preload("res://bullet01.tscn")
var bullet :Node = bullet_scene.instance()
bullet.rotation_degrees = rot
to instantiate a bullet node.
At this point, your BulletFactory becomes an empty scene. So maybe just remove
BulletFactory.tscn from AutoLoad and delete the scene file. Then add
BulletFactory.gd to AutoLoad, and give it a same name as the previous scene.
A gdscript (which has to inherits Node or its subclass) as an autoload, is the same as a scene as an autoload. Just without those predefined nodes.
This is really helpful thank you.
I figured out my problem.
In one of the functions, there was a blank line. It caused the interpreter to think that a chunk of code was not inside the function, and it executed it, and that spawned some instances.
It took a really long time to find this stupid simple thing.
Anyway, watch your blank lines and spaces in python like languages!
ryanscott | 2020-04-27 13:44