Problem with loaders

Hi, im having a problem trying to load my game from the start when these enemies get to the bottom of the screen.
The error is:
ERROR:GAMEOBJECT: Component ‘/loader_go#game’ could not be found when dispatching message ‘unload’ sent from loader:/loader_go#loader
ERROR:GAMEOBJECT: The collection ‘menu’ could not be created since there is already a socket with the same name.
ERROR:GAMEOBJECT: AcquireResources NewCollection RESULT_OUT_OF_RESOURCES
WARNING:RESOURCE: Unable to create resource: /menu/menu.collectionc: OUT_OF_RESOURCES

function end_game(self)
	msg.post(".", "acquire_input_focus")
	msg.post(self.current_collection, "unload")
	msg.post("#mainmenu", "load")
	self.current_collection = "#main"
end

This is the code in the spawner script to send to the loader script

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("#mainmenu", "load")
	self.current_collection = "#mainmenu"
end

function on_message(self, message_id, message, sender)
	if message_id == hash("start") then
		msg.post(self.current_collection, "unload")
		msg.post("#main", "load")
		self.current_collection = "#game"
	elseif message_id == hash("proxy_loaded") then
		msg.post(sender, "enable")
	elseif message_id == hash("end_game") then
		msg.post(self.current_collection, "unload")
		msg.post("#mainmenu", "load")
		self.current_collection = "#mainmenu"
	end
end

here is the loader.

You need to wait for the collection to finish unloading before loading it again. You can watch for a proxy_unloaded message to achieve this.

4 Likes

if you dont mind, what would be the lines of code to achieve this? every other proxy is loading perfectly fine with the exact same code

Check this example: Proxy