<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Unity 3D Help on sk33lz</title><link>https://sk33lz.com/help/unity-3d/</link><description>Recent content in Unity 3D Help on sk33lz</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><copyright>&amp;copy; Jason Moore {year}</copyright><lastBuildDate>Sun, 09 Sep 2018 00:00:00 +0000</lastBuildDate><atom:link href="https://sk33lz.com/help/unity-3d/rss.xml" rel="self" type="application/rss+xml"/><item><title>Using Unity Scene Manager</title><link>https://sk33lz.com/help/unity-3d/using-unity-scene-manager/</link><pubDate>Sun, 05 May 2019 00:00:00 +0100</pubDate><guid>https://sk33lz.com/help/unity-3d/using-unity-scene-manager/</guid><description>&lt;p>The &lt;a href="http://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html">Unity Scene Manager&lt;/a> was introduced in Unity 5.3 and changes the way that scenes are loaded in the game. Many, if not all of the old Application.LoadLevel function has been deprecated in Unity 5.3 for the new Scene Manager code. This guide will help upgrade C# code we found that was deprecated during this update related to scene loading and getting information such as the current loaded scene. The good thing is that everything that you currently have in your game is still going to work until you can get around to updating the deprecated code. It will just give you some annoying warnings with notices like the following:&lt;/p>
&lt;pre>&lt;code>Assets/Scripts/someScript.cs(10,12): warning CS0618: 'UnityEngine.Application.LoadLevel(string)' is obsolete: 'Use SceneManager.LoadScene'
Assets/Scripts/someScript.cs(20,22): warning CS0618: 'UnityEngine.Application.loadedLevelName' is obsolete: 'Use SceneManager to determine what scenes have been loaded'
&lt;/code>&lt;/pre>&lt;p>I had quite a time trying to find the right code to use to fix these issues, as the documentation is pretty lacking so far. I figured I would need the information again probably, so I figured it would be helpful for other Unity developers getting these warnings since updating to Unity 5.3 also.&lt;/p>
&lt;h2 id="lets-clean-up-those-notices">Let&amp;rsquo;s Clean Up Those Notices!&lt;/h2>
&lt;h3 id="add-the-scene-manager-namespace">Add the Scene Manager Namespace&lt;/h3>
&lt;p>First we need to make sure any script files we are modifying to use the new Screen Manager functions have the proper using Directive namespace added. Add the following line of code to any C# scripts that you will be modifying to use Scene Manager.&lt;/p>
&lt;pre>&lt;code>using UnityEngine.SceneManagement;
&lt;/code>&lt;/pre>&lt;h3 id="search-and-replace-applicationloadlevel">Search and Replace Application.LoadLevel&lt;/h3>
&lt;p>Next we want to search and replace all instances of&lt;/p>
&lt;pre>&lt;code>Application.LoadLevel
&lt;/code>&lt;/pre>&lt;p>with the following code:&lt;/p>
&lt;pre>&lt;code>SceneManager.LoadScene
&lt;/code>&lt;/pre>&lt;p>You should end up with something like the following code after upgrading to use with Scene Manager:&lt;/p>
&lt;pre>&lt;code>SceneManager.LoadScene(&amp;quot;Level1&amp;quot;);
&lt;/code>&lt;/pre>&lt;h3 id="search-and-replace-scenemanagerloadsceneapplicationloadedlevel">Search and Replace SceneManager.LoadScene(Application.loadedLevel);&lt;/h3>
&lt;p>Because we have already done a search and replace on SceneManager.LoadScene, we can use that to find and replace any instances of where we used to use Application.LoadLevel(Application.loadedLevel); with the new Scene Manager way of calling that function. Find and replace&lt;/p>
&lt;pre>&lt;code>SceneManager.LoadScene(Application.loadedLevel);
&lt;/code>&lt;/pre>&lt;p>with the following code:&lt;/p>
&lt;pre>&lt;code>SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
&lt;/code>&lt;/pre>&lt;h3 id="search-and-replace-applicationloadedlevelname">Search and Replace Application.loadedLevelName&lt;/h3>
&lt;p>Finally we need to find and replace all the remaining Application.loadedLevelName functions with the new Scene Manager function. Find and replace&lt;/p>
&lt;pre>&lt;code>Application.loadedLevelName
&lt;/code>&lt;/pre>&lt;p>with the following code:&lt;/p>
&lt;pre>&lt;code>SceneManager.GetActiveScene().name
&lt;/code>&lt;/pre>&lt;h2 id="troubleshooting">Troubleshooting&lt;/h2>
&lt;p>I ran into a few issues that were mistakes on my end that I wanted to point out for others.&lt;/p>
&lt;h3 id="dont-forget-the-namespace">Don&amp;rsquo;t Forget the Namespace!&lt;/h3>
&lt;p>The functions will not work unless you add the Scene Manager namespace at the beginning of your C# script file.&lt;/p>
&lt;pre>&lt;code>using UnityEngine.SceneManagement;
&lt;/code>&lt;/pre></description></item></channel></rss>