# Whats the text format used to serialize collections?

**URL:** <https://forum.defold.com/t/whats-the-text-format-used-to-serialize-collections/72707>\
**Category:** Questions\
**Created:** [February 21, 2023, 1:53pm UTC](https://forum.defold.com/t/whats-the-text-format-used-to-serialize-collections/72707 "2023-02-21T13:53:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![carabalonepaulo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/carabalonepaulo/32/20683_2.png) [@carabalonepaulo](https://forum.defold.com/u/carabalonepaulo)\
**Post date:** [February 21, 2023, 1:53pm UTC](https://forum.defold.com/t/whats-the-text-format-used-to-serialize-collections/72707/1 "2023-02-21T13:53:42Z")

</div>

I’m experimenting with Defold and one thing I noticed is that is really hard create things in runtime, everything needs to be setup beforehand.

I created a project and I have several different scenes/collections, each one is a different test. The problem is that I don’t want to manually create a proxy and add it to the main collection (the bootstrap one).

I read a bit about editor scripts and I can see some potential here, I can execute routines based on certain hooks or event actions (like an option on the context menu). So my plan is:

- Create an editor script to list all test collections
- Generate a new collection (it will be used as bootstrap) and embed proxies for each test.
- Save this collection and set it as the bootstrap one.
- Execute this routine before the game is launched.

This way I can create new tests and I won’t need to manually do all this repetitive work for each one.

Problems with this approach:

- I have no idea what is the text format used to save collections, don’t the grammar/rules.
- Don’t know if there is already a library to directly serialize a lua table as a collection text file.
- Don’t know if there is a better way to solve my problem.

* * *

I have other questions too:

- Why Defold make it so hard to create things in runtime? Even with resource.load I still need to have a preallocated slot on my collection to “replace” (maybe I got this wrong).
- Why do I need a factory for each game object/collection? The same applies for proxies. Can’t a single one be used to load any game object? Does Defold uses this approach to optimize something behind the scenes? Is it worth?

* * *

I’m still learning about the engine and I’m not sure if I’m on the right track.

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [February 21, 2023, 2:38pm UTC](https://forum.defold.com/t/whats-the-text-format-used-to-serialize-collections/72707/2 "2023-02-21T14:38:38Z")

</div>

Others are better placed than me to provide more detailed technical answers.

However, this:

> [@carabalonepaulo](#):
>
> Why Defold make it so hard to create things in runtime?

Is answered by this:

> [@carabalonepaulo](#):
>
> Does Defold uses this approach to optimize something behind the scenes?

Fundamentally, Defold is not a dynamic engine.

> [@carabalonepaulo](#):
>
> Is it worth?

As with everything, there is a trade off. This is how the engine is designed. Evidently it creates a harder workflow for you, however I am sure there are significant optimisation benefits that result from this approach.

It does sound like you are “fighting” the design of the engine, which leads me to believe that either a) you need to get used to a different approach, or b) it’s not the engine for you.

We’re happy to help if you have any further questions!

---

<div class="post-metadata">

**Author:** ![carabalonepaulo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/carabalonepaulo/32/20683_2.png) [@carabalonepaulo](https://forum.defold.com/u/carabalonepaulo)\
**Post date:** [February 21, 2023, 3:13pm UTC](https://forum.defold.com/t/whats-the-text-format-used-to-serialize-collections/72707/3 "2023-02-21T15:13:22Z")

</div>

> [@Alex\_8BitSkull](#):
>
> It does sound like you are “fighting” the design of the engine, which leads me to believe that either a) you need to get used to a different approach, or b) it’s not the engine for you.

Indeed, Defold doesn’t seems to be the best solution for my use case 😢  
It’s not a problem to not have this ability (create/generate resources at runtime) if you can do it at “compile time”, but if none is possible then it becomes a problem for me.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 21, 2023, 3:31pm UTC](https://forum.defold.com/t/whats-the-text-format-used-to-serialize-collections/72707/4 "2023-02-21T15:31:30Z")

</div>

The format itself is [Protobuf](https://github.com/protocolbuffers/protobuf), and we have our `.proto` files in the [repo](https://github.com/defold/defold/find/dev), and the generated `*_pb2.py` files are in the [defoldsdk.zip](http://d.defold.com/stable/) (along with the .proto files).

With this, you can read/write the proto files as you wish.

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [February 22, 2023, 9:34am UTC](https://forum.defold.com/t/whats-the-text-format-used-to-serialize-collections/72707/5 "2023-02-22T09:34:38Z")

</div>

> [@carabalonepaulo](#):
>
> I have other questions too:
> 
> - Why Defold make it so hard to create things in runtime? Even with resource.load I still need to have a preallocated slot on my collection to “replace” (maybe I got this wrong).
> - Why do I need a factory for each game object/collection? The same applies for proxies. Can’t a single one be used to load any game object? Does Defold uses this approach to optimize something behind the scenes? Is it worth?

Please read this piece of manual: [Defold project settings](https://defold.com/manuals/project-settings/#component-max-count-optimizations)

Also, this post might be useful: [Defold 1.4.3 BETA - #16 by AGulev](https://forum.defold.com/t/defold-1-4-3-beta/72645/16)

Long story short: all the components and GOs, under the hood are reused by the engine. Let’s name it pools for simplicity. So you don’t create/remove objects, you just increase/decrease the count of components currently used. To make it more efficient all the pools are  
allocated in advance, which helps to keep [Data Locality](https://gameprogrammingpatterns.com/data-locality.html) which needs for cache coherence.
