# \[SOLVED\] How can I reload my scene?

**URL:** <https://forum.defold.com/t/solved-how-can-i-reload-my-scene/74700>\
**Category:** Questions\
**Created:** [October 27, 2023, 6:14am UTC](https://forum.defold.com/t/solved-how-can-i-reload-my-scene/74700 "2023-10-27T06:14:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gamedevshrimp](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gamedevshrimp/32/44402_2.png) [@gamedevshrimp](https://forum.defold.com/u/gamedevshrimp)\
**Post date:** [October 27, 2023, 6:14am UTC](https://forum.defold.com/t/solved-how-can-i-reload-my-scene/74700/1 "2023-10-27T06:14:42Z")

</div>

Hello, dear community! It’s me again. At this time I was stuck on reloading scene.  
I follow this [public example](https://github.com/britzl/publicexamples/tree/master/examples/menu_and_game)  
And I’ve added some changes to reload. Here is my code:

```lua
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.
> 
> ![Screenshot 2023-10-27 at 08.12.00](https://forum-defold-uploads.b-cdn.net/original/3X/8/a/8a33eae444e24cd1aa81fab39fcea8de5b00675f.png)

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 27, 2023, 6:24am UTC](https://forum.defold.com/t/solved-how-can-i-reload-my-scene/74700/2 "2023-10-27T06:24:25Z")

</div>

If you select a collection root you see that it has a name:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/0/3/0344624e958c6b613f7e99bca54825a79e0c84a0.png)

You can not load a collection if another collection is loaded with the same name. It seems like you have more than one `base_level` loaded.

---

<div class="post-metadata">

**Author:** ![gamedevshrimp](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gamedevshrimp/32/44402_2.png) [@gamedevshrimp](https://forum.defold.com/u/gamedevshrimp)\
**Post date:** [October 27, 2023, 6:47am UTC](https://forum.defold.com/t/solved-how-can-i-reload-my-scene/74700/3 "2023-10-27T06:47:09Z")

</div>

> 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

```lua
elseif message_id == hash("reload_game") then
		msg.post("#base_level", "unload")	
		msg.post("#base_level", "load")

```

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 27, 2023, 6:50am UTC](https://forum.defold.com/t/solved-how-can-i-reload-my-scene/74700/4 "2023-10-27T06:50:26Z")

</div>

> [@gamedevshrimp](#):
>
> Yes, that is why firstly I’ve tried to unload the current scene, and after that load it again

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.

---

<div class="post-metadata">

**Author:** ![gamedevshrimp](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gamedevshrimp/32/44402_2.png) [@gamedevshrimp](https://forum.defold.com/u/gamedevshrimp)\
**Post date:** [October 27, 2023, 6:55am UTC](https://forum.defold.com/t/solved-how-can-i-reload-my-scene/74700/5 "2023-10-27T06:55:11Z")

</div>

I got it, thank you

---

<div class="post-metadata">

**Author:** ![gamedevshrimp](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gamedevshrimp/32/44402_2.png) [@gamedevshrimp](https://forum.defold.com/u/gamedevshrimp)\
**Post date:** [October 27, 2023, 2:05pm UTC](https://forum.defold.com/t/solved-how-can-i-reload-my-scene/74700/6 "2023-10-27T14:05:41Z")

</div>

This message is very useful and solved my problem so want to repost it to my topic

> [@How to restart a level? (SOLVED)](https://forum.defold.com/t/how-to-restart-a-level-solved/16698/3):
>
> The method I use is to send a restart message to my controller script that unloads the proxy and sets “self.restart = true” Then check the boolean in the “proxy\_unloaded” message to reload it from there: --check if proxy should reload itself if message\_id == hash("proxy\_unloaded") then if self.restart == true and sender.fragment == hash("myproxy") then msg.post("/proxies#myproxy", "load") self.restart = false end end
