You can try these steps with an empty project.
- Create the loader.script like this:
local hashes = {
did_init = hash 'did_init',
restart = hash 'restart'
load = hash 'load',
unload = hash 'unload'
proxy_loaded = hash 'proxy_loaded',
proxy_unloaded = hash 'proxy_unloaded',
enable = hash 'enable',
disable = hash 'disable',
init = hash 'init',
final = hash 'final',
}
local urls = {
this = msg.url '.',
game_proxy = msg.url '#game_proxy' -- id of your proxy component
}
function init(self)
msg.post(urls.this, hashes.did_init)
end
function on_message(self, message_id, message, sender)
if message_id == hashes.did_init or message_id == hashes.proxy_unloaded then
-- start proxy loading
msg.post(urls.game_proxy, hashes.load)
elseif message_id == hashes.proxy_loaded then
-- init and enable a loaded proxy
msg.post(sender, hashes.init)
msg.post(sender, hashes.enable)
elseif message_id == hashes.restart then
-- disable, deinit and unload proxy
msg.post(urls.game_proxy, hashes.disable)
msg.post(urls.game_proxy, hashes.final)
msg.post(urls.game_proxy, hashes.unload)
end
end
- Change the id of your main collection from ‘default’ to ‘main’.
- Add the ‘root’ gameobject to the main.collection.
- Attach the loader.script component to this object.
- Attach the ‘game_proxy’ collection proxy component to this object.
- Create your game collection that you want to reload and set it in the collection proxy properties.
- When you want to reload your game collection just post ‘restart’ message to your loader script:
local hashes = {
restart = hash 'restart'
}
local urls = {
-- we need a full url with main collection id
-- beacuse we are in the other proxy world.
loader = msg.url 'main:/root#loader'
}
...
msg.post(urls.loader, hashes.restart)