Let’s say I have objects, starships for example, created by a (collection)factory.
I want those starships able to shoot bullets, bullets being objects.
Can I put a factory “create instances of bullet.go” in the script “starship.go”, while 'starship.go" is already an instance created by another factory “create instances of starship.go”.
Fact : There will be a LOT of starships simultaneously, and I fear the engine could not live with so much factories. Or is it the SAME factory for all the instancied objects ?
You can put a factory in an object created by another factory, BUT since each factory will create the same bullet.go instances it will be a waste of resources to have more than one bullet factory. I would move the bullet factory to some centralized game object.
bullet_manager.go has bullet_manager.script and one bullet.factory - it’s the only way bullets are spawned in the game! That’s how I structure this stuff anyway.
I don’t know the intricacies of your project structure, but the whole point of what britzl and I are saying is that you don’t need to do that. Every starship can factory.create(bullet_manager#bullet) and use the resulting bullets as it wishes. The factory doesn’t need to be on the same game object.
Wait, you mean I don’t need to include the factory in the object where I want to create instances as childs ? That’s completely different that the tutorials says.
Here with another example :
Basically, Galaxy create a map of the galaxy, and need for that Stars, which are created by the collection factory StarSystem.collectionfactory.
Each star have planets (and planets can have moons).
main.collection = That s the game scene
* camera.go
* curseur.go
* galaxy.go
galaxy.go = play the galaxy (the map).
* galaxy.script
* StarSystem.collectionfactory = Create the stars. Called in galaxy.script in Init
StarSystem.collection = called by StarSystem.collectionfactory (of course)
* StarSystem.go = Play each star (when created, then when triggered), contain components and a label object (this one put directly in the "outline" tab).
Now, each star has planets
I want to know if, in StarSystem.collection, I have to put a “planet.collectionfactory” that would call :
planet.collection = play the planet (if triggered)
planet.go (with components like script and sprites, of course).
Basically, each star is an object, each planet is an object.
The videos about factories all put the factory where the instancied object would be if it was alone (non instancied), or here : https://defold.com/manuals/factory/.
There is nowhere a word you can put a factory anywhere “up” and call it freely (but it’s great).
Last question : When you say “top level” object, it means some parent, even if it’s not in the same collection ?
Like :