• 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 siddharth3322 · May 30, 2014 at 07:40 AM · movementfreezeunity4.3hiccup

Game Freeze on Start Up

Basically I am working on 2D game development. When I start game, it will freeze two or three frames on start up and then work normally.

At present my game is in starting phase and I don't know why this is happening?

So I provide details about what I have done in my project. This game is vertical scrolling game. So I move my backgrounds in vertical manner one by one. My main character moves horizontally based on player touch.

On game play start, I provide constant velocity to my background and adding force to my main character for movement.

As per my consideration I have to put loading screen so that everything loaded for game and then resume game for actual playing.

On three devices I checked my game but no change in output. Per device I found different freezing that was strange for me. For poor configuration device, I found more poor behaviour.

If you have any idea about problem then please guide me in this.

Comment
Add comment · Show 5
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 siddharth3322 · May 30, 2014 at 07:46 AM 0
Share

I have found this link

http://answers.unity3d.com/questions/56102/methods-to-avoid-game-freezes-when-working-with-fo.html

But don't know how much this become useful to me.

avatar image fafase · May 30, 2014 at 07:55 AM 1
Share

Would you happen to be created a lot of things in the Start of your scripts?

If it is the case, you may want to consider using a loading screen (GUI or GUITexture) to hide the loading, and you keep it on for like 3s with all control disabled and then you remove the GUI and allow the game to run normally.

avatar image Aithoneku · May 30, 2014 at 08:09 AM 1
Share

@siddharth3322 I don't think that the method described under the link is useful - in theory, it can help, yeah, but I would avoid this solutions, because:

  1. It becomes much harder to follow this rule when project becomes bigger.

  2. It moves some of the freeze reasons from first frame to the second, but some freezes will be still visible. It's just distributed between two frames.

  3. I believe the biggest freezes are caused by physics which simulates all the objects before the physics calms down.

  4. I don't believe you can avoid the freezes completely. But the solution of @fafse is one I recommend - display static color or image for first few frames before everything calms down.

avatar image fafase · May 30, 2014 at 08:46 AM 0
Share

On top of that, the loading screen makes your game look professional :)

avatar image siddharth3322 · May 30, 2014 at 09:11 AM 0
Share

Thanks friends all these suggestions. I will analyse all these things and reply you shortly.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Aithoneku · May 30, 2014 at 08:00 AM

This is just a guess, because I would need much more info (including the scene) to be sure, but I think this is highly probable;

when scene, sub-scene is loaded or prefab is instantiated, Unity needs to start these objects (initialize components), which includes:

  • Call Start() on the most of the components.

  • Call Awake() on the most of the components.

  • Register collides in collision system. (This might be done during loading - I don't know.)

  • Load static meshes, textures, shaders, etc. to graphic memory. (This might be done during loading - I don't know.)

  • More things depending on used components

Then, first few frames are really heavy:

  • Physics simulates all the object before they "calm down". (I think this is the main reason of the freezes.)

  • Maybe your objects (depending on your implementation) registers their existence somewhere and look around themselves.

The freeze will be much longer with bigger scenes (more game objects and components).

I believe it's unavoidable in the most of the cases, so IMHO it's not possible to solve, but it's possible to hide this problem and make the user experience fluent.

My solution, in last project I was working on, is through fading screen - it's a game object + component which fades in and out when switching between scenes. When scene is loaded, I wait a few frames before fading in. Example workflow:

  1. When a scene is loaded, display black screen (or any other color or static image). Game is paused.

  2. Wait a few frames (I used 10). Now the FPS is really bad, but because you display static color or image, user doesn't see this.

  3. Fade into the scene.

  4. Unpause the game. Now player can play.

Now scene is played. When you want to load other scene:

  1. Pause the game.

  2. Fade out (to black screen or anything else).

  3. When the screen is completely faded out, load new scene.

  4. When the new scene is loaded, black screen is displayed so user doesn't see any problems. Again, wait few frames and fluently fade into the scene.

With this I was able to achieve 100% fluent transitions between scenes even when the scene was really big one with lot's of physically simulated objects.

Comment
Add comment · Show 3 · 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 siddharth3322 · May 30, 2014 at 09:10 AM 0
Share

Thanks for all these master suggestions. Now I will check for this and reply you shortly.

At present, I am using Application.LoadLevel() method. I have to try for other one or not?

avatar image fafase · May 30, 2014 at 09:21 AM 1
Share

In order to create a loading screen, you need simply to start a coroutine that will display the texture over the whole screen for a determined amount of time.

 void Start()
 {
     guiTexture.enabled = true;
     StartCoroutine(LoadingScreen());
     // Plenty of code to create and place object
 }
 
 IEnumerator LoadingScreen()
 {
    $$anonymous$$anager.SetState(State.Loading);
    float t = 0;
    while( t < 3){
        t+= Time.deltaTime;
        yield return null;
    }
    Destroy(guiTexture);
    $$anonymous$$anager.SetState(State.Running);
 }

This is a simplified version, the state is used in all scripts to check when you should be able to start playing:

 void Update(){
   if($$anonymous$$anager.GetState() == State.Loading)return;
 
   // Plenty of code with Input and movements.
 }
avatar image siddharth3322 · May 30, 2014 at 10:01 AM 0
Share

Thanks @fafase, I will try this thing and reply you. I think you have to put it as answer to help other members also.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

21 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

Related Questions

Move Object Using iTween 2 Answers

Main character always attached with ground 1 Answer

Apply Constant Force 2 Answers

Line Collision Detection for 2D Game 1 Answer

Creating a castle-crasher-like Game [Need Help] 3 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