Lack of information about using dynamic prototype setting for collection factory

I’m trying to generate level consisted of different rooms. Rooms are just collection of different object and enemies in it. I tried to use collection factory to generate new rooms on the fly. But when I want to change prototype of collection factory from script using collectionfactory.set_prototype() function, I receive this error “Failed to load collection factory prototype /game/levels/room_001.collectionc”. Tried to follow example listed in Collection factory manual, but looks like it not working. On other hand changing prototype for OBJECT FACRORY work fine. What I want it’s create pool with different rooms named like room_001, room_002 etc. and pick random one and spawn.
My project structure
Screenshot_5
Collection factory properties
image
Outline of main collection
image
Error


Factory script
image

I do something similar but I use multiple collection factories. Randomize which one gets called.

1 Like

The documentation for collectionfactory.set_prototype(url, prototype) expects prototype to be a project path. In your case it looks like it should be /game/levels/level_2.collection.

I tried that too and its not helped, because for some reason when building the project all other collection not build into collectionc, only one collection defined in collection factory does.

Please, take a look at this old post about the Dynamic Prototype feature to make sure you use it in the way it was initially designed:

Our build system builds only linked resources. If you never link the resource anywhere, it will not be built. A ‘linked resource’ in this case means being specified in a factory or in some other place specific to that resource. It’s not enough to be in the project folder.

If you want to have a few levels in your game, just create a few collection proxies (or collection factories).

4 Likes

Because I need to use some pivot for a sprite (need nested game objects for that) I use collections for this. For game object’s factories with dynamic prototypes one can trick the build system with the collection proxy which includes all such game objects. But it doesn’t work for collections and collection factories.
Any workarounds? I need a lot (50+) of such collections and to me creating a factory for every of this collections smells, or is it fine?
Are there any downsides of using collection factory with dynamic prototypes which often reloads them, if I will find a workaround?

In 1.9.5, we’ll introduce pivot points for images in atlas files. It should improve upon a lot of cases where there is an extra game object simply to offset the sprite.

Yes, have read about this announcement, but I guess I still will need a collection for my use case to nesting some other things.

Maybe its XY problem, but I have the same problem as OP, but instead of few rooms (for which you surely can create additional collection factories), I have some 50+ smaller collections.

So my question could you trick the build system somehow now? Is it wise to use collection factory with dynamic prototype and such amount of collections?

If all of those collections have a similar layout, you might be able to replace them with just one collection, then use factories and the various Defold APIs to spawn and configure the necessary objects at runtime.

Yes, they are similar layout, but the problem is that defold doesn’t allow to change all properties at runtime (or makes it much harder). Like properly position of shapes of colliding objects etc.

For now I have created another collection, that collects all this collectionfactories. It is kinda works.