• 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 /
This question was closed Jul 21, 2017 at 10:32 PM by asdfadsfgadfg for the following reason:

The question is answered, right answer was accepted

avatar image
Question by asdfadsfgadfg · Jul 11, 2017 at 03:13 AM · errorvariablescene-loadingasyncasynchronous

Can't access AsyncOperation instance to change allowSceneActivation

I'm trying to load a scene in the background, initially setting allowSceneActivation to false, then setting it to true once a button is placed. When I try to set it to true, though, Unity gives me an error, saying 'Object reference not set to an instance of an object'. the variable in question is, indeed set to an instance, though, in the Start function:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Events;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class GameLauncher : MonoBehaviour {
     AsyncOperation async;
 
     // Use this for initialization
     void Start () {
         //load other scene in background
         StartCoroutine(loadScene());
         //connect to server in background
     }
 
     public IEnumerator loadScene()
     {
         async = SceneManager.LoadSceneAsync(1, LoadSceneMode.Single);
         async.allowSceneActivation = false;
         yield return null;
     }

here's where I get the error:

     public void Connect () {
         //finish connection when button is pressed
         async.allowSceneActivation = true;
     }

I don't get why thIs assignment in the loadScene coroutine doesn't count? Is the Connect function being public somehow responsible? It's hard to troubleshoot, since Unity crashes every time I fail to finish the scene load...

Comment

People who like this

0 Show 0
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

2 Replies

  • Sort: 
avatar image
Best Answer

Answer by asdfadsfgadfg · Jul 21, 2017 at 10:32 PM

The problem as stated isn't reproducible, it was a misunderstanding.

Comment

People who like this

0 Show 0 · 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

Answer by _watcher_ · Jul 15, 2017 at 03:38 PM

Just a guess - try using LoadSceneMode.Additive ? Your script and further execution is removed as soon ad the new scene using LoadSceneMode.Single is loaded (because it resides in your previous scene).

Comment
asdfadsfgadfg

People who like this

1 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 asdfadsfgadfg · Jul 21, 2017 at 10:30 PM 0
Share

thanks for your reply! And sorry it took me so long to respond. The problem turned out to be much dumber than I thought; there were two buttons in the scene, and the one which had been linked properly was disabled. So allowSceneActivation was never being set to true after all.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

90 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

Related Questions

Odd behaviour when preloading multiple scenes 1 Answer

SceneManager.LoadScene used within promise (or async callback) does nothing 0 Answers

Loading scene with LoadSceneAsync freezes and progress jumps from 0% to 90% 2 Answers

Unexpected symbol CS1525 2 Answers

AsyncOperation activating immediately even with async.allowSceneActivation = false; 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