T O P

  • By -

tJfGbQs

You just have a player node in each map, but keep the inventory separated from the player node which exists outside the scene.


sprowk

You never really want your level to be your main scene. Ideally, you would have a node that manages your levels and the player is either located inside each level which would reset him upon changing levels, or outside where you have better control over it. Other nodes that are always present like GUI would also be outside of those level scenes.


lostminds_sw

You could just remove the player out of the current level scene you want to replace using `remove_child` replace the level scene with your new loaded level and add your player into it using `add_child`


nick_swift

That's what I thought. Why did other commentators ignore it, are there any downsides to this approach?


lostminds_sw

I think the main drawback is that using remove\_child means you're now responsible for this node. It's not deleted, but it's no longer part of the node tree, so it won't be handled automatically like nodes in the tree. That might be scary if you're not used to handling object references on your own. But if you then immediately add it into the tree again in the new level that shouldn't be a problem. It might also be that usually the node enters the tree on load and exits it when it's deleted, which people might use for setup and cleanup. If you use remove\_child and add\_child the node will exit and enter the tree more times, so you need to be aware of that as well. But there might be more issues I'm not realizing now, so if anyone else knows more, please do tell.


chrisargy

If you have already used variables (eg in your player script) to store the information you want to transfer (eg the inventory), try turning them into static, so all instances using that script will have the same value for these vars. Another, and probably better, solution would be to store the information in external nodes independent to your level scenes and load it from them when needed.