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
1
Question by Xylph · Sep 25, 2015 at 08:09 PM · androidserializationfreezestucksplashscreen

Stuck on splash screen on Android only

I have a very weird problem that I've been trying to resolve for hours. I get stuck on the Unity splashscreen when running the game in an Android device. I've tried standalone platforms and WebPlayer and it worked fine.

Since June, I stopped building on platforms and focused on testing in the editor only. But before that, I can build just fine in Android. I am actively updating the project to the newest Unity 5.x (if that matters)

Here's the "technical" explanation of what's happening whenever the game is loaded:

  • The game only has one scene. No need for Application.LoadLevel

  • On Awake of the objects that are preloaded in the scene, some of my scripts are creating instances of prefabs. This instances will contain initial/default data.

  • I have a script called GameLoader which is the entry point of all my code (like a bootstrap)

  • On Start of GameLoader, it starts a coroutine which initializes the modules of my game step-by-step.

  • The first process is to load the save file. The save file is in JSON stored in PlayerPrefs as string. This will be parsed into a JToken (Json.NET). So far, the game still loads up to this point.

  • The next process in loading the save file is to deserialize the json into Unity objects. I wrote my own script for this. In this process, I use System.Type.GetType and System.Type.GetInterface to check if a gameobject has a component which implements my serialization interface. This process will update ALL existing objects.

  • Once everything's deserialized, I initialize all modules of the game since they already have data to work on.

  • Lastly, I enable the UI (main canvas).

I tested this by interrupting the code one by one (using return) until the game loads. Whenever I comment out or skip out the function which loads the save file, the game loads. However, like I said earlier, this was working before.

I'm thinking if Android has the watchdog timer (in iOS) which kicks the app out whenever you're doing something heavy on startup. Although it takes less than a second to load the save file and deserialize it. I'm not sure if something changed in 5.1 and 5.2 that turned my code into an undocumented bug or if it's related to the android SDK I've installed.

Here's my serialization code which bridge the Json parser and Unity API. It might ring a bell. If you need more information, please say so. Thanks.

 public static GameObject Deserialize(GameObject go, JObject json, bool includeChildren = false)
     {
         go.name = (string)json["go_name"];
         IEnumerable<string> keys = json.Properties().Select(p => p.Name).ToList();
 
         foreach (string key in keys)
         {
             try
             {
                 // Check if type exists
                 Type type = Type.GetType(key, true);
 
                 // Check if type is serializable
                 if (type.GetInterface(typeof(IJsonSerializable).ToString()) == null) continue;
 
                 // Create component and add it to the GameObject if it's not created yet
                 IJsonSerializable component = go.GetComponent(type) as IJsonSerializable;
                 if (component == null) component = go.AddComponent(type) as IJsonSerializable;
 
                 // Deserialize
                 if (json[key] != null) component.Deserialize(json[key]);
             }
             catch
             {
                 // Type does not exist, continue to the next json object
                 continue;
             }
         }
 
         if (includeChildren)
         {
             // Deserialize child game objects
             JToken children = json["go_children"];
             if (children != null)
             {
                 foreach (JObject child in children)
                 {
                     GameObject childGo = Deserialize(child);
                     childGo.transform.SetParent(go.transform);
                 }
             }
         }
 
 
         return go;
     }




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

2 People are following this question.

avatar image avatar image

Related Questions

How do i fix this splash screen fade freeze on android 2 Answers

Serialization: Marshal.StructureToPtr does not work "always" 0 Answers

Why APK freezes at start of game level? 0 Answers

Why my game in Android freezes when calling LoadScene ? 2 Answers

What might cause an Android app to freeze 1 Answer


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