Hello!
I am working on a 3D, first person game which currently has 3 scenes. A core gameplay mechanic requires picking up and then dropping items. To manage the trick, gameobjects are parented to the player and everything is turned off until dropped, when everything is turned on again and the parenting is cleared. This mechanic works well within a single scene; however, I am having trouble transferring the game objects into other scenes. In one instance, the game object is instantiated into the next scene, in another, it is not. I can't figure out why these are behaving differently. Here's some more detail:
1. In Scene 1, pick up item A.
2. Pick up actionlist runs the following: Disable hotspot, turn off visibility, set parent to Player prefab constantID, add relevant inventory item.
3. Navigate to Scene 2 via a player-detecting trigger which runs Scene:Switch Scene 2.
4. In Scene 2, the player prefab is spawned at the playerstart marker linked to Scene 1.
Result: The game object item A is spawned in Scene 2, and parented to the player. Hotspot is disabled, visibility is off, and it is still part of the inventory.
1. In Scene 1, pick up item A.
2. Pick up actionlist runs the following: Disable hotspot, turn off visibility, set parent to Player prefab constantID, add relevant inventory item.
3. Navigate to Scene 0 via a player-detecting trigger which runs Scene:Switch Scene 0.
4. In Scene 0, the player prefab is spawned at the playerstart marker linked to Scene 1.
Result: The game object item A is not instantiated in Scene 0.
Does anyone know what could cause a difference in behaviour?
The item is a prefab, and has a constantID, remember hotspot, remember transform, remember visibility. The prefab is located in the \Assets\Resources folder.
Thank you for spending some time thinking about it!
Comments
Is there a local instance of your Player prefab located in Scene 0? If there is, that will override the "persistent" Player prefab that the game begins with in Scene 1. You could test this out by renaming the player in Scene 1, and see if he still has the same name when moving to Scene 0.
Are you needing to parent the objects for the purposes of showing them in view of the camera? If not, I would instead recommend forgetting about the parenting method and try simply removing objects from view instead. If you place an instance of each transferrable object in each scene (but use Retain in prefab? to ensure they all have the same ID number), your ActionLists that reference by ID number will still work in any scene.
While adding/removing objects during gameplay is possible through careful use of RememberTransform components and placement in the Resources folder, it's generally much easier to simply hide and show objects from view if you can get away with it.