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
5
Question by ParadoxSolutions · Feb 22, 2016 at 05:55 AM · c#scenemanagergameobject.findhow to

SceneManager: how can I find GameObject in another scene?

So I have a sceneManager script in the active scene and so if I use GameObject.Find it will only find gameobjects in the same scene that the script is in correct? What I would like to do is find a GameObject that is in another loaded scene and I can get the root objects with this:

SceneManager.GetSceneByName(sceneToLoad).GetRootGameObjects(); I have made it so there is only 1 root GameObject so how can I accesses it because I want the root objects transform.position value but this returns an array.

My only other option it seems is to move the sceneManager script and ALL other GameObjects it is using over to the other loaded scene, getting the transform.position value then moving it all back to the original scene and that is not a very good way to do it in my opinion.

A SceneManager.FindGameObjectInScene(GameObject go, Scene name); would be very helpful, should request it to be added.

Comment
Add comment · Show 2
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
avatar image hexagonius · Feb 22, 2016 at 09:01 AM 0
Share

the return value never switches to a single value if it's able to return multiple. in your case the returned array should have one entry. use [0] on it to get your root object

avatar image ParadoxSolutions hexagonius · Feb 23, 2016 at 12:11 AM 0
Share

Yes it will return [0] since there is only one GameObject in the array but how can I get the GameObject the 0 in the array represents so I can get it's position from it's transform?

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by jgodfrey · Feb 23, 2016 at 01:26 AM

You want something like this:

 gameObject[] goArray = SceneManager.GetSceneByName(sceneToLoad).GetRootGameObjects(); 
 if (goArray.Length > 0)
 {
    gameObject rootGo = goArray[0];
    // Do something with rootGo here...
 }
Comment
Add comment · Show 1 · 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
avatar image ParadoxSolutions · Feb 23, 2016 at 01:35 AM 0
Share

I swear I tried this though but it seems to work now, thanks.

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

111 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

Related Questions

how to spawn a player prefab on a server 0 Answers

There is a problem with my script... 0 Answers

[SOLVED] How to load next level? 0 Answers

Reading from file (C#) + Information from scene to scene (C#) 0 Answers

how do i take whats on one UI canvas and make it apear on another in real time(for a card game) 0 Answers


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