I would like to be able to set properties on a factory that it in turn will pass on to the gameobject it creates. We have gameobjects that are the same in all aspects except for a few script settings, and as it is now I need to either figure out in code which enemy should be created and pass those properties or create different gameobjects that only differs in script property settings.
Could you elaborate a bit about your use-case? Don’t your code already have to figure out which factory to use to create the game object?
The use case in this case is (not super easy to explain, so bare with me):
- We have gameobjects that are spawners which spawns enemies. The spawners differ on enemy type (sprite, sound, particlefx, etc), but each enemy type can contain several variants of the same enemy. Example: There is a spawner for enemy “skeleton” but there are several levels of skeleton (“skeleton_1”, “skeleton_2” etc).
- I have a unified gameobject with factories that will create a spawner of a certain kind. Right now I need a gameobject for each level of skeleton “skeleton_spawn_1”, “skeleton_spawn_2” etc that in turn calls a factory on a similar gameobject with factories for all enemies. The only difference between the gameobjects is a setting on a script that tells the spawner what kind of enemy to spawn
- What I would like to do is have each spawn factory (“skeleton_spawn_1”, “skeleton_spawn_2” etc) create a the same gameobject and be able to set a property on the factory that in turn is set on the spawner gameobject
Ok. However, I don’t understand why you can’t have one spawner go with one factory and pass the properties on creation:
local enemy = factory.create("#enemy_factory", nil, nil, { type = 1, health = 10 })
As I understand it you want to put the “type = 1” etc in the factory component, right?
Yes, that is currently the way I am doing it (allthough the example I gave was a simplified version of what we are trying to achieve so that is not entirely true) - but since it might be someone who is not a coder who will be in charge of enemy balancing I would like for them to be able to set that in the editor instead of in code (which is one of the big strengths in Defold imho)
Ok, I see now. Thanks.