How to use factory pattern correctly? (Cannot find prototype) (SOLVED)

Hi! I’m new to the engine and I’m trying to explore factories but having some problems.

Let me preface the question with the current component structure I have:

+-- circle.collection
|   +-- circle (game object)
|     +-- circleSprite (sprite)
+-- main.collection
|   +-- circleInstance (game object)
|     +-- circleFactory (collection factory, prototype is circle.collection)
    +-- main.script

I can call collectionfactory.create() from main.script and spawn a collection without an issue. But since the prototype collection has only one game object in it, calling the collection feels strange. So instead, I have tried to replace my circleFactory with a regular factory that would point the circle object as a prototype. However I don’t see any other game objects in the prototype section, so I can’t do this. I’ve come across some older posts about prototypes not appearing in the list, so I’ve tried restarting the editor multiple times to no avail.

So most likely, I’m doing something wrong in the way I’m arranging things. My end goal is to spawn/destroy/modify objects created via the factory in my main.script.

Hopefully someone can point me to the right direction!

Cheers

1 Like

Do you think that you can zip the game and post it here so that I can take a look at it. This seems like a weird issue, mat maybe there is a small little hiccup you’re forgetting.

Thanks, you can take a look here:
Circles.zip (550.4 KB)

Update:
I was able to set the factory prototype to an object if the target object is not in a collection, but it’s standalone in a folder. Is this the expected behavior?

Create a Game Object file on the left pane

And then you would be able to select this file as a prototype.

After that you would be able to create instances in the code

6 Likes

Thanks Sergey, this actually works. Also, really appreciate the example in main.script :slight_smile:

2 Likes

Yes, some assets need to exist as files on disk in the Asset Panel. The factory component expects a game object file (eg foobar.go), the collection factory and collection proxy expects a collection file (foobar.collection). And when you want to add a particle effect to a game object or gui you need to create a particle effect component file (foobar.particlefx). There are other similar examples of components and files that need to exist on disk as opposed to certain more lightweight components that can exist inline in a collection.

1 Like

Thanks for the clarification!