How do I get component's url If I create object with factory API?(SOLVED)

Hi guys, I’m trying create Roguelike game.
I want to switch tile-maps with every floor,
because of this I created object with factory API, and I got tile as follows.

-- Create game object that has tile-map.
local floor_name = "floor1_factory"
self.floor = factory.create(floor_name)
pprint(self.floor) -- hash("/instance0")

-- Get tile from other script.
local x = 1
local y = 1
local tile = tilemap.get_tile("/instance0#tilemap", "layer1", x, y) -- Now, URL is hard-coded.

I want to get URL like a “/instance0#tilemap” as string.
How do I get component’s URL, if I create object with factory API.

1 Like

You get the url of the thing created with the factory with msg.url() and then you set the fragment of the url with url.fragment = “tilemap” or whatever. Then you can use the url with component fragment included.

This code may not be right for what you are doing but hopefully it gets the idea to you.

local floor_name = "floor1_factory"
self.floor = factory.create(floor_name)
local url = msg.url(self.floor)
url.fragment = "tilemap"
local tile = tilemap.get_tile(url, "layer1", x, y)
3 Likes

Thank you!
I solved it as you said.
I was misunderstanding about URL.