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 /
avatar image
0
Question by Pranav47 · Nov 25, 2019 at 04:03 PM · scripting problemcoroutinescene-loadingcrashingwebrequest

Unity keep crashing when loading scene from a couritne (Unity 5.x)

I am trying to send a POST request to an API and load a scene when the![alt text][1]script gets a response, but it's crashing the Unity.

Version 5.x

Thanks in advance.

 using System.Collections;
 using UnityEngine;
 using UnityEngine.UI;
 
 using UnityEngine.Networking;
 using UnityEngine.SceneManagement;
 
 public class LogInGamer : MonoBehaviour
 {
     [SerializeField] private CredentialsConfig credentialsConfig;
     [SerializeField] private  string PORT;
     [SerializeField] private  string ServerLink;
     [SerializeField] private string sucsessfulLoginScene;
 
     [SerializeField] private InputField gamerIdInputField;    
     [SerializeField] private InputField gamerPasswordInputField;
     private  string gamerId = "";
     private string password = "";
     private IEnumerator coroutine;
     private bool _isLoggedIn;
     [SerializeField] private GameObject registrationPanel;
 
     private void Start() {
         PORT = credentialsConfig.PORT;
         ServerLink = credentialsConfig.URL;
     }
 
     public void ActivateRegistationPanel()
     {
         registrationPanel.SetActive(true);
     }
 
     public void TakeIdInput()
     {
         gamerId = gamerIdInputField.text;
     }
 
     public void TakePasswordInput()
     {
         password = gamerPasswordInputField.text;
     }
 
     public void HitLogInApi()
     {
         coroutine = LogIn();
         StartCoroutine(coroutine);
     }
 
     IEnumerator LogIn()
     {
         WWWForm form = new WWWForm();
         form.AddField("gamerid", gamerId);
         form.AddField("password", password);
         form.AddField("projectId", credentialsConfig.projectId);
 
         using (UnityWebRequest www = UnityWebRequest.Post(ServerLink + ":" + PORT + "/unity/login", form))
         {
             www.SetRequestHeader("Accept", "application/json");
 #if !UNITY_5
             yield return www.SendWebRequest();
 
             if (www.isNetworkError || www.isHttpError)
             {
                 Debug.Log(www.error);
             }
             else
             {
                 Debug.Log("Form upload complete!");
                 if(www.responseCode == 200)
                 {
                     this.gameObject.SetActive(false);
                 }
                 var c = www.downloadHandler.text;
                 Debug.Log("Response-> " + c);
             }
 #else
             yield return www.Send();
 
             if (www.isError)
             {
                 Debug.Log(www.error);
             }
             else
             {
                 Debug.Log("Form upload complete!");
                 if (www.responseCode == 200)
                 {
                     //SceneManager.LoadSceneAsync(sucsessfulLoginScene, LoadSceneMode.Single);
                     SceneManager.LoadScene(sucsessfulLoginScene, LoadSceneMode.Single);
                 }
                 var c = www.downloadHandler.text;
                 Debug.Log("Response-> " + c);
             }
 #endif
         }
 
     }
 }


Comment
Add comment · Show 4
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 Bonfire-Boy · Nov 25, 2019 at 04:27 PM 0
Share

First, don't post code in screenshots. Use the code button (101010) ins$$anonymous$$d.

Second, look in your log file and let us know what that says about the crash.

avatar image lgarczyn · Nov 26, 2019 at 04:37 AM 0
Share

Also check that removing the script stops the crash.

avatar image Pranav47 lgarczyn · Nov 26, 2019 at 04:49 AM 0
Share

Yes, I have checked it and this is only the one script Unity Project has. After removing these lines works fine but I want to change the scene if login is successful.

 //Scene$$anonymous$$anager.LoadSceneAsync(sucsessfulLoginScene, LoadScene$$anonymous$$ode.Single);
 Scene$$anonymous$$anager.LoadScene(sucsessfulLoginScene, LoadScene$$anonymous$$ode.Single);

Thanks

avatar image Bonfire-Boy Pranav47 · Nov 26, 2019 at 08:21 AM 0
Share

You really need to look at the log file https://docs.unity3d.com/$$anonymous$$anual/LogFiles.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by yolkfolk · Nov 26, 2019 at 05:59 AM

You're not instantiating sucsessfulLoginScene anywhere.

In Unity, go to File > Build Settings, and set your sucsessfulLoginScene to one of the values in "Scenes In Build". For example, sucsessfulLoginScene = "Scenes/LoginScene".

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

214 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

Related Questions

Why isn't my scene transition coroutine working? 1 Answer

> 0.9f progress of SceneManager.LoadSceneAsync isn't 0 Answers

How to disable a script on a bunch of instantiated objects with tag ? 1 Answer

Can't call of type IEnumerable with delegates? 1 Answer

Weird problem with Async Task and UnityWebRequest 4 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