# How to set atlas property from factory?

**URL:** <https://forum.defold.com/t/how-to-set-atlas-property-from-factory/75331>\
**Category:** Questions\
**Created:** [December 14, 2023, 7:43pm UTC](https://forum.defold.com/t/how-to-set-atlas-property-from-factory/75331 "2023-12-14T19:43:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RisingSunStudios](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/risingsunstudios/32/27482_2.png) [@RisingSunStudios](https://forum.defold.com/u/RisingSunStudios)\
**Post date:** [December 14, 2023, 7:43pm UTC](https://forum.defold.com/t/how-to-set-atlas-property-from-factory/75331/1 "2023-12-14T19:43:10Z")

</div>

Hi again.

If I have a script with `go.property("my_atlas", resource.atlas("/atlas.atlas"))` defined, how do I set this when the instance is created from a factory?

```lua
local props = { health = 50, target = msg.url("player") }
local id = factory.create("#can_factory", nil, nil, props)

-- Accessing to factory created script properties
local url = msg.url(nil, id, "can")
local can_health = go.get(url, "health")

```

`resource.atlas(...)` can only be used inside of go.property() as stated by the API documentation.

If I have a hundred atlases (I will likely end up with more and currently generate them in my external editor..) and want to dynamically select which one to use, how do I accomplish this?

---

<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:** [December 14, 2023, 10:00pm UTC](https://forum.defold.com/t/how-to-set-atlas-property-from-factory/75331/2 "2023-12-14T22:00:06Z")

</div>

> [@RisingSunStudios](#):
>
> If I have a hundred atlases (I will likely end up with more and currently generate them in my external editor…) and want to dynamically select which one to use, how do I accomplish this?

Interesting problem! If you have hundreds of them you don’t want to use `go.property("my_atlas", resource.atlas("/atlas.atlas"))` since all of them will be in memory at once.

What I would do is to per atlas create one dummy game object file with a sprite which references the atlas. Each dummy game object is referenced from a factory with the Load Dynamically checkbox set.

When you want to use an atlas you load the resources used by the correct factory using `factory.load()`. This will load the atlas into memory after which you can set it on your game objects.

---

<div class="post-metadata">

**Author:** ![RisingSunStudios](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/risingsunstudios/32/27482_2.png) [@RisingSunStudios](https://forum.defold.com/u/RisingSunStudios)\
**Post date:** [December 14, 2023, 10:45pm UTC](https://forum.defold.com/t/how-to-set-atlas-property-from-factory/75331/3 "2023-12-14T22:45:40Z")

</div>

Thanks for the reply! That’s actually exactly what I’m doing at the moment, but thought might be an easier way.

I am very glad the game object and atlas files are raw text and easy to generate in external tools - I wouldn’t want to make all the atlases and add all the factory components by hand!

---

<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:** [December 15, 2023, 12:51pm UTC](https://forum.defold.com/t/how-to-set-atlas-property-from-factory/75331/4 "2023-12-15T12:51:15Z")

</div>

> [@RisingSunStudios](#):
>
> That’s actually exactly what I’m doing at the moment, but thought might be an easier way.

We’ve talked about adding an option to not automatically load resources referenced in a script property. Once we have that it will be a lot easier to set up something like this.
