Arbitrary scene graph hierarchy at runtime

Hi,

I’ve just started using Defold, and it is a very nice engine, indeed :).

I have a (million, but let’s start with this one) question: I want to create an arbitrary hierarchy of objects at runtime, and what I’ve done so far is creating a factory that spawns empty GameObjects that I then move around with “set_parent”.

Is there any way of creating those empty GameObjects without having to create a factory with an empty .go file attached? It seems like a hack :smiley:

Thanks in advance!

No. If you want to create game objects at runtime you need to use a factory. You can instantiate hierarchies of game objects created in collections with collection factories.

Thanks for your response!

Where should I open a feature request? Creating empty GameObjects seems like a sensible thing to have in the engine, seeing that they’re needed for the whole scene graph to work

What’s the purpose of these empty game objects? Will they not have a single component? If so, will their position, scale and rotation be manipulated by scripts attached to other game objects?

1 Like

The place would be the feature requests section of this forum, but I’m curious about your specific use case. First of all, when do you want to create empty GameObjects? The reasons I can see is creating a graph for doing things like spring systems and the like. What is your specific requirement? Technically, it would be trivial to add something like this to the API, but we also want to keep the API to a minimum so we try to only add things when there is a reasonable need for it.
The reason you have to define the factories with proper references (as opposed to being able to do resource acquisition from script, which is quite common in other engines), is that this creates a static resource tree of everything that is needed to run the game. We can then use this tree for many good things, the most obvious being including only what you use when making bundles for distribution.

Thank you both for replying, really appreciate it :slight_smile:

In my game I create objects at runtime that are defined by some player actions. Those objects are combination of other objects, and I use the scene graph to be able to easily manipulate them from my scripts (rotating or moving a parent instead of calculating positions for all of them, etc)

I understand that you want to keep the API to a minimum (a good thing indeed) and that the information is useful at building time (although being able to create empty objects wont change that as far as I can see, given that those new objects don’t have any resources attached… but as I said, just started playing with this engine ;))

1 Like

Ah ok, so it’s something along the lines of spatial group management? That makes sense. The build time stuff is just an explanation for the factory components, as you say it really has nothing to do with empty game objects created on the fly.
Feel free to add it as a feature request (simplifies tracking issues). Hope you enjoy the engine and keep the questions coming! :slight_smile: