Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 YoYoooooooo · Dec 03, 2013 at 02:42 PM · loadleveladditive

What is the state of GameObjects just after they have been loaded through a Application.LoadLevelAdditive() call?

Hi,

there is something I misunderstand about Application.LoadLevelAdditive(): If I try to get GameObjects loaded just after a call to this method located in a Start callback, GameObject.Find() returns null for any object. So It seems that loaded GameObjects are only "avalaible" one frame later. That might mean they are activated with a 1 frame delay after they have been loaded.

Ok, then what confuses me is that the Start method of every scripts attached to these objects gets called, letting me think we are still in the first frame.

So GameObjects can not be retrieved through GameObject.Find(), but their scipts seem to be executed. What is their real state? Active? Not active? Almost active?... :-)

Any explanation welcome!

yoyoooooooo

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 YoYoooooooo · Dec 09, 2013 at 03:10 PM 0
Share

No one knows? Or is the question stupid?

3 Replies

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

Answer by YoYoooooooo · Dec 11, 2013 at 01:42 PM

Ok, thanks for your contributions. Mixing both your answers, here is my finding: 1) loaded game objects are accessible through GameObject.Find() from the frame just after the frame that called LoadLevelAdditive() 2) callbacks such as OnEnable and Start are called int that same subsequent frame

My mistake was to think that the Start() callback was only called in the first frame.

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
avatar image
0

Answer by Statement · Dec 09, 2013 at 03:29 PM

I was under the impression that the objects are loaded in last during the same frame, so they all exist on your next frame. That said, this is more of a guess and showing how you can deduce what happens yourself.

  • On the object that loads your scene, do a Debug.Log.
    Use Time.frameCount to figure out what the current frame is during that call.

  • On an object that is loaded in your additive scene, on Awake and Start, do a Debug.Log.
    Use Time.frameCount to figure out what the current frame is during those calls.

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
avatar image
0

Answer by Guts · Dec 09, 2013 at 03:44 PM

This is definitely NOT a stupid question! I wanted to find out myself what was going on, so I made 2 scenes: Scene1 and Scene2.

Scene1 is empty except for the main camera, to which I attach this script:

 using UnityEngine;
 using System.Collections;
 
 public class LevelLoader : MonoBehaviour 
 {
     void Start () 
     {
         Application.LoadLevelAdditive("Scene2");
         GameObject findMe = GameObject.Find("FindMe");
         if (findMe == null)
         {
             Debug.Log("FindMe was null in the same frame as the LoadLevelAdditive call.");
         }
         else
         {            
             Debug.Log("FindMe was NOT null in the same frame as the LoadLevelAdditive call.");
         }
         StartCoroutine(CheckNextFrame());
     }
 
     IEnumerator CheckNextFrame()
     {
         yield return new WaitForEndOfFrame();
         GameObject findMe = GameObject.Find("FindMe");
         if (findMe == null)
         {
             Debug.Log("FindMe was null in the next frame after the LoadLevelAdditive call.");
         }
         else
         {            
             Debug.Log("FindMe was NOT null in the next frame after the LoadLevelAdditive call.");
         }
     }
 }

Scene2 is empty except for a Cube which I've renamed "FindMe". I attach this script to the FindMe object:

 using UnityEngine;
 using System.Collections;
 
 public class FindMe : MonoBehaviour 
 {
     void Awake()
     {
         Debug.Log("FindMe Awake");
     }
 
     void Start() 
     {
         Debug.Log("FindMe Start");
     }
 
     void OnEnable()
     {
         Debug.Log("FindMe OnEnable");
     }
 }

When I play Scene1 (after making sure that I've added Scene1 and Scene2 to the build settings), I get the following output.

  1. FindMe was null in the same frame as the LoadLevelAdditive call.

  2. FindMe Awake

  3. FindMe OnEnable

  4. FindMe Start

  5. FindMe was NOT null in the next frame after the LoadLevelAdditive call.

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

18 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

Related Questions

LoadLevelAdditiveAsync + Lightmap index 1 Answer

Split-screen for a large world 0 Answers

How to load a DDOL scene additively on startup ? 3 Answers

Game Level question, instantiate or loadlevel? 1 Answer

Intermittent crash on LoadLevelAdditive, and LoadLevelAdditiveAsync 2 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