# Get url of child component of game object created with factory? (SOLVED)

**URL:** <https://forum.defold.com/t/get-url-of-child-component-of-game-object-created-with-factory-solved/3804>\
**Category:** Questions\
**Created:** [December 29, 2016, 5:57pm UTC](https://forum.defold.com/t/get-url-of-child-component-of-game-object-created-with-factory-solved/3804 "2016-12-29T17:57:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dapetcu21](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dapetcu21/32/25120_2.png) [@dapetcu21](https://forum.defold.com/u/dapetcu21)\
**Post date:** [December 29, 2016, 5:57pm UTC](https://forum.defold.com/t/get-url-of-child-component-of-game-object-created-with-factory-solved/3804/1 "2016-12-29T17:57:17Z")

</div>

My usecase:

I have a game object with just a sprite on it. I create this game object from a factory. I then need to animate its opacity. That’s `tint.w` on the child sprite (not on the game object itself). So question is, how do I access the sprite?

```lua
local piece = factory.create(msg.url("my_factory"), position)
local sprite_url = piece + "#sprite" -- This won't work since piece is a hash
go.animate(sprite_url, "tint.w", go.PLAYBACK_ONCE_FORWARD, 0.0, go.EASING_LINEAR, 0.4)

```

EDIT: I managed to do what I needed to do by placing a script on the game object and doing the animation there, but it feels like there should be a way to do it directly.

---

<div class="post-metadata">

**Author:** ![AJirenius](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ajirenius/32/2257_2.png) [@AJirenius](https://forum.defold.com/u/AJirenius)\
**Post date:** [December 29, 2016, 7:39pm UTC](https://forum.defold.com/t/get-url-of-child-component-of-game-object-created-with-factory-solved/3804/2 "2016-12-29T19:39:22Z")

</div>

Best way I guess is to use msg.url()

```
local piece = factory.create(msg.url("my_factory"), position)    
local url = msg.url(piece)
url.fragment = "sprite"
go.animate(url, "tint.w", go.PLAYBACK_ONCE_FORWARD, 0.0, go.EASING_LINEAR, 0.4)

```

---

<div class="post-metadata">

**Author:** ![dapetcu21](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dapetcu21/32/25120_2.png) [@dapetcu21](https://forum.defold.com/u/dapetcu21)\
**Post date:** [December 29, 2016, 8:30pm UTC](https://forum.defold.com/t/get-url-of-child-component-of-game-object-created-with-factory-solved/3804/3 "2016-12-29T20:30:39Z")

</div>

I didn’t know you can set the fragment on an url. Thanks!
