If i know only a path to "go1" can i build a url to a sub object in the created collection? (SOLVED)

I am creating collections from factory.
In collection:
root_game_object
root_game_object\go1
#script
How to create url to “\go1” in function init(self) of new collection ?
That do not work:

  1. go.get_id() … “/go1”
  2. url = msg.url(); url. path = “go1”

Urls are not dependent on game object nesting. So, in your case, “root_game_object” and “go1” would be siblings, so you can do msg.url(“go1”) from root_game_object’s init().

If you work with collection factories, remember that collectionfactory.create returns you a table of all the created game objects. With that you can do created_gos[hash(“root_game_object”)] to get the url of the root and created_gos[hash(“go1”)] to get the url to go1.

1 Like

If you want to receive path to internal go of spawned collection in init(), you have to use go.get_id() with relative path to your object, in your case go.get_id(“go1”)
docs: https://www.defold.com/ref/go/#go.get_id:-path-

1 Like

Thanks to everyone. That halped.

1 Like