- Home /
 
How to know parent scene of the object?
Hello.
Is there any way to know parent scene of the gameobject in the unity?
I searched in the google and community. But I couldn't find any way.
Help me.
Thank you.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by NorthStar79 · Aug 10, 2017 at 06:48 AM
Check this out buddy.
 using UnityEngine;
 using UnityEngine.SceneManagement; //this is important, pay attention here
 
 public class SceneNameLog: MonoBehaviour {
 
 
     private void Start()
     {
 
      string s = gameObject.scene.name;  //you can get scene index too.
      Debug.Log(s);
     }
 
              Answer by Elthen · Aug 10, 2017 at 06:30 AM
If I've understood correctly you're looking for the current scene; You can get it by using GetActiveScene, like so:
 Scene scene = SceneManager.GetActiveScene();
 Debug.Log(scene.name); //print the scene name
 
               Remember to also import:
 using UnityEngine.SceneManagement;
 
                
              Thank you very much.
Your comment is very helpful for me.
Your answer