Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 snowconesolid · Jan 05, 2012 at 07:55 PM · fbxlag

Reducing Lag in Game?

So Iv been working on my game for some time now and lately im starting to realize its becoming really laggy. I was wondering if there is any way to reduce this lag? My level only has 3 houses, my main character, and the base area for the player to walk on and houses to stay on. I was wondering if I scale down the whole level and everything inside of it like objects, houses, everything, down to really really small size, would that reduce the lag in my game?

I am not using High poly models, Im only using the low poly models iv been working on, however they are all FBX files. But really my game is pretty much like a N64 game, In terms of Models, textures, and animations. but still it lags for some reason, and I am becoming worried because I still need to add a lot more things to the level such as other characters and more objects, and collision features and other scripting stuff. Lagging at an early stage is not a good sign.

Comment
Add comment · Show 6
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 Randomman159 · Apr 11, 2014 at 02:07 PM 0
Share

Old post I know, but in case others run by here, it's worth noting that the scale of things in your game is nothing to worry about. If you decide to up everything 100 fold, so your game goes from -1000 to 1000 ins$$anonymous$$d of -10 to 10, it will not cause lag.

Coordinates are simply that, coordinates. It doesn't require more memory, nor is it slower to work with large floats than it is to work with small floats.

avatar image derekwsparks · Jun 11, 2014 at 06:03 AM 0
Share

I am running into the same issue with my scene and game. Restarting Unity has no effect at all. I don't have the greatest of computer nor the worst. $$anonymous$$aybe a little below todays average in terms of ram and performance but I can play Assassins Creed Black Flag on low settings with $$anonymous$$imal lag so Im assu$$anonymous$$g that Ive done something to effect the performance somehow. As far as I know all of my models are .fbx as well which is what Ive read you should use.

I have between 20 -25k trees with colliders the map is a 3000 by 3000 height 300. In areas with little to no models such as buildings the lag is $$anonymous$$imal or non existant but at my Church Yard which has of course the Church and behind is the grave yard the lag is fairly bad.

I made a development build of my game which is 406 mb. Not even a gig so I figure it shouldnt be as bad as it is. When I run the build if I set it to windowed at 800x600 it is decent with only a little lag in the church yard.

Any advice or more info need to give advice?

avatar image BenLuker · Feb 15, 2017 at 07:38 AM 0
Share

If anyone is still having this problem I just finished making my game run smoother by changing my Update functions to contain as little intensive work in them as possible. Here's what I mean, let's say that you control your character's inputs through the update function. If you ever want to take control away from your character (for a tutorial or cutscene for example) it might seem reasonable to set up a boolean canPlayerMove and set it to true or false depending on the situation. Your script would look something like this:

     void FixedUpdate () {
         if (canPlayerMove = true) {
             if(Input.GetKey (KeyCode.A)) {
                 transform.position += Vector3.left * movementSpeed * Time.deltaTime;
             } else if (Input.GetKey (KeyCode.D)) {
                 transform.position += Vector3.right * movementSpeed * Time.deltaTime;
             }
         }
     }
 
     // This function let's the player move
     public void PlayerStart () {
         canPlayerMove = true;
     }
 
     // This function prevents the player from moving
     public void PlayerStop () {
         canPlayerMove = false;
     }


However, now your Update method is checking whether or not canPlayerMove is true every single frame. Stuff like this is what will lag your game, so finding creative solutions to these types of problems is going to be what helps you. A solution to this problem might be turning the canPlayerMove boolean into an integer that is either 1 or 0 and multiply it to the transform.position. Here's what that would look like:

     void FixedUpdate () {
         if(Input.GetKey (KeyCode.A)) {
             transform.position += Vector3.left * movementSpeed * Time.deltaTime * canPlayerMove;
         } else if (Input.GetKey (KeyCode.D)) {
             transform.position += Vector3.right * movementSpeed * Time.deltaTime * canPlayerMove;
         }
     }
 
     // This function let's the player move
     public void PlayerStart () {
         canPlayerMove = 1;
     }
 
     // This function prevents the player from moving
     public void PlayerStop () {
         canPlayerMove = 0;
     }
 
 }

The resulting code is functionally the same, but now you are checking for less things and your game would run more smoothly. I hope this helps if anyone needs it.

PS: This theoretical setup I explained was actually something in my game and after making these changes it heavily improved the performance.

avatar image tanoshimi BenLuker · Feb 15, 2017 at 09:04 AM 0
Share

While I agree with your sentiment, I find it hard to believe that that particular example made any appreciable difference in performance. Sure, you've removed one (incredibly fast) boolean test each frame. But you've added one (very fast) multiplication and an implicit int -> float cast every frame ins$$anonymous$$d!

avatar image annonymushubh BenLuker · Jul 24, 2017 at 03:28 PM 0
Share

if i change The Update() Function to FixedUpdate() then can i resolve this type of problem

avatar image Mrstixk012 · Apr 21, 2017 at 07:28 AM 0
Share

me i lag and i have just 3 house with a road and in the stats its write i do 117 FPS but i feels the lag

5 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by mpavlinsky · Jan 05, 2012 at 08:31 PM

I wouldn't worry too much, I'm sure you can get this resolved and add everything you want especially if it's not graphics intensive. You probably just need to adopt more efficient scripting and graphics practices.

If you have Unity Pro the profiler built into Unity is good and can give you great insight into what is bogging you down. Barring that you can find some information about doing graphics optimizations here, and there is some information about optimizing scripts here.

Comment
Add comment · Show 1 · 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 snowconesolid · Jan 05, 2012 at 08:46 PM 0
Share

You are right, looks like I was worried for no reason. I just closed unity and reopened it and it runs smooth again on gameplay, it must of become laggy when I was importing my models for some reason. Even better I just made a build of the level Im working on to test it out, Its file size is pretty small (only 8mb, so far)

surprisingly it runs extremely smooth in the actual build. I feel a lot better now. haha.

avatar image
0

Answer by chesterhilly · Jun 15, 2015 at 09:10 AM

In Mobile Development, change the materials to mobile shaders. This really can improve framerates but the textures look not as good

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

Answer by chesterhilly · Jun 15, 2015 at 09:11 AM

By the way, I just fixed my lag by about 5 fps to about 50 fps. I had the annoying little error that says "NullReferenceException...." This was because I had to put a gameobject and make it into a prefab and then assign it to the other prefab variable.

THIS SHOWS THAT WHEN YOU FIX ERRORS IT CAN REALLY IMPROVE FRAMERATES

Comment
Add comment · Show 1 · 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 toddisarockstar · Apr 21, 2017 at 03:37 PM 0
Share

no one should ever leave any errors in any game! Not only does it obviosly slow a game, but they can also make your game do wierd stuff like skip other non-related sections code.

avatar image
0

Answer by toddisarockstar · Apr 21, 2017 at 03:27 PM

I'm glad you found your problem was just in the editor! anyways looks like others are following this question. So i thought i would add for anyone who does have a level too large. First of all scale does not matter! what matters is the number of faces and amount of textures sent to the video card! A cube as small as a rock or scaled large as a building requires the same amount of processing power to display!

so generally you never use more faces in your models than needed and as less textures as possible.

Unity has something called batching which by default is running during your game. it does help with ignoring textures not in use and reducing shader quality at distances but Its really not enough for a really big world.

there is a technique called LOD which uses simpler meshes at a distance. https://docs.unity3d.com/Manual/LevelOfDetail.html

there is also a setting to reduce texture quality at a distance https://docs.unity3d.com/ScriptReference/Texture-anisoLevel.html

of course you can do stuff with code for your game too. an example would be simply disabling game objects or complex meshes when you know they are out of view with code. Such as the detailed inside of a building or room when the user is outside!

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

Answer by Joe-Censored · Apr 21, 2017 at 04:20 PM

Just to add another performance tip, while developing I'm often a bit liberal with the debug.log calls, outputting different values where I'm trying to debug my code, and then sometimes not immediately disabling them when issues get figured out with the intention of cleaning up all these log calls before release. While trying to figure out my own performance problems though I discovered that Debug.Log outputs are actually very expensive, much more than I expected. A few Debug.Log calls per update can bring your game to a crawl.

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

14 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

Related Questions

unity application getting slow 0 Answers

Lag issues with unity3d + Arduino (Xbee) 0 Answers

Import Glass Square into Unity (Cinema 4d, fbx) 1 Answer

Unity 3D - Model Failure! Please HELP ME!!! 0 Answers

FBX mesh not showing up in game 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