Dynamic Prototype property for factories not documented

Hi!

I can’t find any documentation about Dynamic Prototype property for factory and collection factory component.

image

I only found the commit for the changes and on “PR Checklist” the documentation is also unchecked :wink: If I recollect correctly it was roughly described in some release notes.

I’ll make sure to update the documentation tomorrow!

1 Like

Factory component updated: Factory component manual

3 Likes

Hi, could you please also add something about .goc files? It seems like the environment requires to load .goc files for dynamic prototypes but I did not find anything about it in the documentation. I tried to simply rename .go file to .goc but it did not work.
Thanks.

The binary versions of Defold data files have a ‘c’ appended to their extensions, for instance .goc for a compiled .go file, .spritec for a compiled .sprite and so on. The files are in binary protobuf format and created by the build tools. As you probably understand now you can’t use a .go file and rename it .goc since it will still be in the verbose protobuf text mode format which is not supported at runtime.

So let’s say you have two factories in your game, factoryA and factoryB, and they can spawn two different game objects, /game/enemyA.go and /game/enemyB.go. Now if you want factory A to spawn enemyB instead of enemyA, you can do like this:

factory.unload("#factoryA")
factory.set_prototype("#factoryA", "/game/enemyB.goc")
local enemy_of_type_b = factory.create("#factoryA")
2 Likes

That means I had a wrong path to the prototype all the time. :sweat_smile: I think I was so confused by the extension that I didn’t look more thorough in other files. I often struggle with paths to everything… :frowning:

Thanks for your help, it works now. :slight_smile:

1 Like