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
0
Question by dabandabanda · May 15, 2019 at 01:25 AM · gameobjectscene-loadingscene changemulti-display

Scene Manager and Keeping Objects when Loading/Unloading + Gameogject.SetActive not working:(

Hey! I'm in a bit a pickle. I'll tell you what I'm trying to achieve first. It's a first-person "fighter game" where you're interacting with robots (one at a time) placed in different environments with separate HDRI maps. There should be a "base scene" that never unloads - containing its own camera, controller, score-manager, and the robots themselves (one robot per scene). If a robot was punched and fell down, it would trigger a new scene to appear containing a new HDRI map and new destroyable objects. The falling robot would land onto a pile of other robots in a separate display that's still part of the "base scene" and would stay there. The falling robot would trigger a new robot to appear (Set.Active) in the "base scene" as well. This is something that I was experimenting with, but couldn't figure out. I got the scene loading and unloading part working, but I can't seem to set new robots active. This script is for the trigger that robots falls through:

 using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.SceneManagement;
         public class acivateRobot : MonoBehaviour {
         public GameObject RobotKyle;
         private void Start()
         {
            RobotKyle = GameObject.FindGameObjectWithTag("Robot3");
             RobotKyle.SetActive(false);
         }
         private void OnTriggerEnter(Collider other)
         {
             if(other.CompareTag("Robot"))
             RobotKyle.SetActive(true);
             this.gameObject.SetActive(true);
             Debug.Log("Kyle is active");
           }
     }

In addition to the script above, I'm running this manager script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 public class AnyManager : MonoBehaviour {
     public static AnyManager anyManager;
     bool gameStart;
     void Awake ()
     {
         if(!gameStart)
         {
             anyManager = this;
             SceneManager.LoadSceneAsync(1, LoadSceneMode.Additive);
             gameStart = true;
         }        
     }
     public void UnloadScene(int SceneNumber)
     {
         StartCoroutine(Unload(SceneNumber));
     }
     IEnumerator Unload(int SceneNumber)
     {
        yield return null;
         SceneManager.UnloadSceneAsync(SceneNumber);
     }
 }

Ans two simple scripts to load and unload scenes if a robot were to fall through another trigger(attached to separate scenes).:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class Load : MonoBehaviour
 {
     public int SceneNumber;
     bool loaded;
     private void OnTriggerEnter(Collider other)
     {
         if (!loaded)
         {
             SceneManager.LoadSceneAsync(SceneNumber, LoadSceneMode.Additive);
             loaded = true;
         }
     }
 }
 
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 public class Unload : MonoBehaviour 
 {
     public int SceneNumber;
     bool unloaded;
     private void OnTriggerEnter(Collider other)
     {
         if (!unloaded)  
         unloaded = true;
         AnyManager.anyManager.UnloadScene(SceneNumber);
     }
 }
 

I would greatly appreciate your help! Perhaps there's a better way to do this? Thanks!

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

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

Unity 5 NullReferenceException after loading new scene. 1 Answer

How to passing levels automatically in games? 0 Answers

How to change transform.position after loadScene? 2 Answers

Lifes count resets with level 0 Answers

Camera not rendering on UnloadSceneAsynch 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