Hello, dear community! It’s me again. At this time I was stuck on reloading scene.
I follow this public example
And I’ve added some changes to reload. Here is my code:
function on_message(self, message_id, message, sender)
if message_id == hash("show_game") then
msg.post("#base_level", "load")
msg.post("#main_menu", "unload")
elseif message_id == hash("reload_game") then
msg.post("#base_level", "unload")
msg.post("#base_level", "load")
elseif message_id == hash("show_menu") then
msg.post("#main_menu", "load")
msg.post("#base_level", "unload")
elseif message_id == hash("proxy_loaded") then
msg.post(sender, "enable")
print('proxy_loaded')
end
end
In the message ‘reload_game’ I’m trying to unload and load my level again
But I got an error
The collection ‘base_level’ could not be created since there is already a socket with the same name.
You can not load a collection if another collection is loaded with the same name.
Yes, that is why firstly I’ve tried to unload the current scene, and after that load it again
elseif message_id == hash("reload_game") then
msg.post("#base_level", "unload")
msg.post("#base_level", "load")
Well, those operations are asynchronous and you are also sending both an “unload” and a “load” message in the same frame. This means that the engine will try to both unload and load the same collection at the same time. You need to wait for the “proxy_unloaded” message before you try to load the same collection again.