Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by kira_resari · May 09, 2020 at 03:22 PM · scene change

Scene transition sometimes does not move character to the correct position

I have the issue that when moving between scenes through doorways, the character is sometimes, but not always not moved to the correct coordinates after the scene change, instead staying at the position where I placed the character in the editor. The same scene change might even randomly work or fail during the same session of play. Currently, the odds of it failing are about 80%, though I get the impression they are lower if I just turned on the computer.

My general scene layout is like this: One character object in every scene One default spawn point in every scene * Several doors (invisible trigger colliders) and an identical number of spawn points

The general scene change transition mechanic is as follows: Every door knows which scene it leads to, as well as the name of the spawn point they lead to When the character enters a door, the name of the target spawn point is saved in a singleton, and the target scene is loaded * When a scene is loaded, the character stored spawn point name is read from the singleton, and the character is automatically teleported to that spawn point (or the default spawn point if no spawn point of that name could be found)

Here's the main Classes I use for that:

For the "Doors" (this script is located on a trigger-collider):

 [RequireComponent(typeof(Collider))]
 public class Teleport_To_New_Scene : MonoBehaviour
 {
     [Tooltip("The name of the scene this 'door' leads to.")]
     public string target_scene_name;

     [Tooltip("The name of the spawn point at which the player should emerge in the new scene.")]
     public string target_spawn_point_name;

     void OnTriggerEnter(Collider collider)
     {
         GameObject entering_object = collider.gameObject;
         if (entering_object.tag == Tags.PLAYER)
         {
             Scene_Change_Controller.Instance.target_spawn_point_name =
                 target_spawn_point_name;
             Scene_Change_Controller.Instance.character_facing =
                 entering_object.transform.rotation.eulerAngles.y;
             SceneManager.LoadScene(target_scene_name);
         }

     }
 }

For the Scene Initialisation (this script is located on an empty "Scene_Init" game object):

 class Field_Scene_Init : MonoBehaviour
 {
     private const string DEFAULT_SPAWN_POINT_NAME = "Default_Spawn_Point";

     void Start()
     {
         Teleport_Player_To_Spawn_Point();
         Set_Player_Rotation();
     }

     private void Teleport_Player_To_Spawn_Point()
     {
         GameObject player = GameObject.FindGameObjectWithTag(Tags.PLAYER);
         GameObject spawn_point = Scene_Change_Controller.Instance.Get_Target_Spawn_Point();
         if(spawn_point == null)
         {
             spawn_point = Game_Object_Finder.Find_Spawn_Point_By_Name(DEFAULT_SPAWN_POINT_NAME);
         }
         player.transform.position = spawn_point.transform.position;
         Debug.Log("player.transform.position: " + player.transform.position);
     }

     private void Set_Player_Rotation()
     {
         GameObject player = GameObject.FindGameObjectWithTag(Tags.PLAYER);
         float target_facing = Scene_Change_Controller.Instance.character_facing;
         player.transform.Rotate(0, target_facing, 0, Space.Self);
     }
 }

The Scene Change Controller (this is a singleton)

 class Scene_Change_Controller : Singleton<Scene_Change_Controller>
 {
     public string target_spawn_point_name = "Default_Spawn_Point";
     public float character_facing = 0f;

     public GameObject Get_Target_Spawn_Point()
     {
         return Game_Object_Finder.Find_Spawn_Point_By_Name(target_spawn_point_name);
     }
 }

I have already tried to debug it in various ways.

Maybe my most interesting finding thus far was by adding a log to the very end of the Teleport_Player_To_Spawn_Point-function to read out the player's coordinates after teleporting. In the log, the correct coordinates are always displayed, regardless of whether the player ends up appearing at the correct coordinates or not.

I've also already checked that there is only one player object present in the scene.

Does anyone have any idea why this is happening, and what I can do about it?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by camdenlink7 · Jan 28, 2021 at 02:12 AM

I wish I knew. I am running into the same problem. Did you ever get it fixed? @kira_resari

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

200 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity look input to get detail and change the scene 1 Answer

Problem with script in multiple scenes needing to refer to FPS Controller. 1 Answer

Loading and Unloading scenes 2 Answers

I don't see my black and white scene file after reinstalling Unity 0 Answers

I have several scenes in 3D, and I want them to change after colliding the player with an object. How do I do this? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges