Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
avatar image
0
Question by KGD_Dude · Dec 11, 2018 at 03:26 AM · scripting beginnerscriptingbasicscamerasscene-changegameobject.find

Can I load new information into GameObjects when a new scene is loaded?

Hello everyone! So as the title says, I was wondering if there is some kind of way to load new info in already defined GameObjects in a script when a new scene is loaded. I'm a bit of a noob at programming, so sorry if I ask things that are impossible : p

So here is what I have now:

 private GameObject Cam1;
 private GameObject Cam2;
 private GameObject Cam3;

 void Awake()
 {    
         Cam1 = GameObject.Find("CameraPosition01");
         Cam2 = GameObject.Find("CameraPosition02");
         Cam3 = GameObject.Find("CameraPosition03");
 }

This a script on the Player. So when the Player gets transfered to a new scene, it should actually completely reload this script to find the new "CameraPosition..."s in the current scene. I tried a couple of things already, but nothing seems to work.

Comment
Add comment · Show 1
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 Vega4Life · Dec 11, 2018 at 03:37 AM 0
Share

This player script is using DontDestroyOnLoad and you want to find the camera positions in the current scene?

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by KGD_Dude · Dec 11, 2018 at 09:07 AM

So, I was able to fix it.

I tried before to place it into "void OnSceneLoaded"

But it seems I had to place this in the beginning:

 void Start()
 {
     SceneManager.sceneLoaded += OnSceneLoaded;
 }

So that did the trick. Thank you guys for the effort : )

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 KGD_Dude · Dec 11, 2018 at 09:41 AM 0
Share

I made a mistake, "void Start" worked for a small moment then stopped working. Fixed it with "void Awake" : )

avatar image
0

Answer by Vega4Life · Dec 11, 2018 at 03:39 AM

If your player is staying around, via DontDestroyOnLoad, then I would listen for a scene change and get the camera positions then.


 void OnSceneLoaded(Scene scene, LoadSceneMode mode)
     {
          Cam1 = GameObject.Find("CameraPosition01");
          Cam2 = GameObject.Find("CameraPosition02");
          Cam3 = GameObject.Find("CameraPosition03");
     }



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 KGD_Dude · Dec 11, 2018 at 08:45 AM 0
Share

So, I tried this "void OnSceneLoaded" but did't seem to work either... What about destroying the script on SceneLoad and adding it again as a new? And there is a script on the player to DontDestroyOnLoad, but it's not in this script. This is not the problem right?

and the "Reset" function that darkStar27 mentioned will not work in a build? only in the editor?

avatar image
0

Answer by darkStar27 · Dec 11, 2018 at 03:40 AM

I haven't tried anything like that yet but i think you can use Reset Reset is used to set the target to a default value.

For more information on rest and how to use it check out this link.

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 Vega4Life · Dec 11, 2018 at 03:43 AM 0
Share

That is an editor only option. :)

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

108 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

Related Questions

Can someone explain calling other scripts in C#? 2 Answers

Changing quality setting on all scenes 1 Answer

How to add force if spherecast is true and how to set direction of sphere 0 Answers

How can I slow the velocity of my player without it affecting fall speed? 0 Answers

How do I make a photography function? 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