# Hot reload a collection loaded with a collection factory

**URL:** <https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335>\
**Category:** Questions\
**Created:** [January 19, 2021, 1:27pm UTC](https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335 "2021-01-19T13:27:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 19, 2021, 1:27pm UTC](https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335/1 "2021-01-19T13:27:46Z")

</div>

I load a level collection with a collection factory. Hot reloading this collection produces this error:

```
ERROR:RESOURCE: /screens/gameworld/level/maps/map18.collectionc could not be reloaded since it was never loaded before.

```

The collection has been loaded and is visible on the screen when this log message appears. What kind of resources can be hot reloaded?

---

<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:** [January 19, 2021, 1:29pm UTC](https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335/2 "2021-01-19T13:29:37Z")

</div>

Collections _should_ be able to hot reload.  
Not sure what goes in this case 🤔

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 19, 2021, 6:19pm UTC](https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335/3 "2021-01-19T18:19:35Z")

</div>

> [@totebo](#):
>
> What kind of resources can be hot reloaded?

I believe all resources can be hot reloaded nowadays.

Can you share a minimal repro case and steps to reproduce? Preferably on GitHub!

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [January 19, 2021, 6:46pm UTC](https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335/4 "2021-01-19T18:46:59Z")

</div>

> [@britzl](#):
>
> I believe all resources can be hot reloaded nowadays.

There are some hoops to jump through to hot reload a lua module though, right?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 19, 2021, 9:10pm UTC](https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335/5 "2021-01-19T21:10:34Z")

</div>

> [@Klear](#):
>
> There are some hoops to jump through to hot reload a lua module though, right?

Yes, that is true. I don’t exactly recall what you need to do though (and yes, I should know!). I think you need to require the module again and you may also need to clear the \_G.packages.loaded[“modulename”] entry.

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [January 19, 2021, 9:51pm UTC](https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335/6 "2021-01-19T21:51:55Z")

</div>

There’s a workaround [here](https://defold.com/manuals/modules/#hot-reloading-modules). I’ve successfully used it in the past.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 21, 2021, 1:57pm UTC](https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335/7 "2021-01-21T13:57:19Z")

</div>

I created an empty project with one line of code:

```
local game_object_ids = collectionfactory.create("#collectionfactory")

```

It produces the error in the first post when hot reloading. My guess is it doesn’t work because Defold loads the collection under the hood when create() is called?

Minimal project just in case: [HotReloadCollection.zip](https://defold-forum-bucket.nbg1.your-objectstorage.com/original/3X/4/7/47850340d6326656f35cf612a293aecaba77e6f1.zip) (2.5 KB)

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 4, 2021, 10:17pm UTC](https://forum.defold.com/t/hot-reload-a-collection-loaded-with-a-collection-factory/67335/8 "2021-02-04T22:17:19Z")

</div>

Note: Created GH issue [Hot reloading a collection created through a collection factory generates an error · Issue #5527 · defold/defold · GitHub](https://github.com/defold/defold/issues/5527)
