Problems with carrying items from scene to scene


Hello again!

I'm here to talk about a smaller system that I had to figure out how to get right for this game to work. That system being the system that allows the players treasures to be moved from one scene to the next when required. The game will have a few major scenes in them, and treasure must be able to be brought through all of them at some point when appropriate. Like when the player comes back from an expedition any treasure that wasn't brought on the ship with them should be deleted, but any that is on the ship should not. This would be a simple case of moving things into the DoNotDestroyOnLoad scene in unity, but if an object gets taken out of it then it should be deleted again. 


To break this issue down into it's major parts there's the system that needs to determine which item needs to remain loaded between scenes and the system that needs to use that data to actually keep the item loaded in the scene. To do this I created a cube that has a trigger hit box. Once that trigger is crossed by an entity the cube will determine if the thing intersecting it is an item with a tag. If it's tagged "Item" then a pointer to the item will be sent to the game manager which has a list of "Collected" items. The Game Manager will then also add this item to the DoNotDestroyOnLoad scene. If the collection cube detects an object tagged Item is leaving it then it will do the same thing, and the game manager will remove it from memory and move the item back into the scene. An issue that can arise with this is the problem where when moving across scenes the cube gets deleted and never informs the Game Manager that they left which effectively means that those items will forever be loaded from then on unless the player moved them into and out of another collection cube. To remedy this I am trying to add a system that will go through the collection list and immediately remove everything out of the list. It's not a very robust solution and I will revisit it later as needed. 

So that's how the game actually transfers items across the scenes without storing and destroying all the items currently.

Until the next post. 

Leave a comment

Log in with itch.io to leave a comment.