Global Indexing with Spawned Objects [SOLVED]

Hullo again, Defold community.
Tinkering more around with Defold, I find that trying to store a factory (or collection-factory) spawned object as a global variable doesn’t work out well.

image

I would try to post a message to it later on (from a different collection / world), like this:
image
and it wouldn’t receive it:

What I’m trying to look for is a way to message pass to the spawned object through a global index, but I’m not really sure how to do it…

Any help would be appreciated~

The problem you are facing is that you are posting a message from one collection to another, but you are only using partial information about the recipient. You have the game object id, which is unique within its world (ie bootstrap collection or loaded collection via a collection proxy) but you don’t have the information about which world it belongs to. You need to store the full URL, and you can construct it from the id like this:

msg.url(nil, id, nil)

When the URL is constructed it will fill in the first part, which is the socket or world automatically. Store this URL instead and use it when posting the message.

1 Like

Alright, I will try that when I get the chance.

It works perfectly! Thank you very much!