Forum rules - please read before posting.

Transferring gameobjects parented to player prefab during scene:switch

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

  • In which version of Unity?  As the Player is marked as "DontDestroyOnLoad", Unity will place the object in a separate scene of its own - and any child objects should also survive, regardless of their Remember components.

    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.
  • Hi Chris,

    I am using Unity 5.4.1f1, 64-bit.

    There is no local instance of the player prefab in Scene 0. I tested it by renaming the Player once in Scene 1, Playerooney is still called Playerooney when I return to Scene 0.

    Thanks for looking into it,


  • Could you post a screenshot of the various Remember components you have on it?  Try temporarily removing the RememberTransform component from it - does it then work?
  • Hi Chris,

    Disabling the remember transform component does not make it work.

    Here are all the remember components and their details:

    • Constant ID = set AUTOMATIC, retain in prefab YES.
    • Remember Transform = save change in parent YES, save scene presence YES, set AUTOMATIC, retain in prefab YES.
    • Remember Hotspot = hotspot state on start ON, set AUTOMATIC,retain in prefab YES.
    • Remember Visibility = visibility on start ON, affect children NO, set AUTOMATIC,retain in prefab YES.

    Thanks again for looking into this.
  • I think this could be down to your use of these scripts in a way that isn't actually intended.  Remember scripts on the Player are treated as objects local to the scene, meaning parenting such objects to your game mid-scene could cause issues.

    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.
  • Hi Chris,

    I was parenting the objects to the player so that when running the action list to drop the item, clearing the parent would allow the object to drop at the position of the player. We didn't need to display the objects in the view of the camera, although it might have been a "nice to have".

    We've gone the route of a custom script to instantiate and teleport the object to the location of the player and that works between scenes. If we encounter trouble further ahead, I'll look back to the "secret stash per level idea".

    Thanks for thinking about it!
  • No problem.  When dealing with complex operations like this, a good general rule is that if you can write a custom Action for it, do so!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.