The issue of “Dynamic Prototype” and goc files in the factory component

I want to use a factory class to dynamically generate various enemies, so I checked the “Dynamic Prototype” option, allowing me to set factory.set_prototype("#factory", "/xxx/xxx.goc") anytime and anywhere. This is good, but the path part is in goc compiled format. Since I don’t plan to add any enemy instances during editing, without adding instances, no goc files will be generated. Without goc files, I can’t dynamically generate them. Therefore, my approach is to pre-add all enemy instances to a collection in an area that the camera will never enter, so the engine can compile the corresponding goc files for me to use. What is the reasoning behind this design, and what would be the most elegant solution?

Since different enemies may need to be generated multiple times per second, would it be more advisable to use a separate factory class to generate each enemy in this case?

Dynamic prototype was originally made for the Live update function that Defold supports, in which compiled files are stored in a .zip or your own server in order to be dynamically loaded into the game rather than being part of the game binaries. To save data, defold will not compile any game instances that are not referenced.

1 Like

Like @mchlkpng writes the dynamic prototype was mainly intended for use with LiveUpdate, but it can be used in other ways too, like your use-case. Instead of putting them in the current “scene” off screen, I’d put the game objects in a separate collection, and reference the collection using a collection proxy. That way the files will be compiled but not loaded into memory.

4 Likes

Yeah, I didn’t mention that cuz it seems they had already implemented such a system

Sure. Having a separate factory for each enemy is the most elegant solution :wink:
“Dynamic prototype” is not needed in 99.9% of cases

3 Likes

tks!