• 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 Fragmental · Nov 09, 2015 at 11:06 AM · 2dlagtopdownroguelike

Horrible lag in 2d roguelike character movement

I'm using a modified version of the game from the 2d Roguelike Tutorial . I've made only slight modifications to the original scripts. I've mainly added new UI elements and scripts to handle those UI elements.

I'm having issues with character movement. In the editor, the characters will mostly move fine, but when I build, all of the characters move, VERY slowly. It takes roughly two full seconds for a character to move into position. Everything else seems to run at full speed, but the cpu usage in the build is much higher than in the editor.

Also, even in the editor, there are still sometimes issues with the player character kind of weaving around and not staying square on a tile, so that if you walk by food it will pick up food on both tiles, etc.

I don't know why any of this happening. There doesn't seem to be any bugs in my code that would cause this, and I don't know why movement would be so much slower in the build rather than the editor, or why cpu usage would jump. Any ideas about what might be causing this?

https://youtu.be/RKtuwGfCxGk here's an example of the slow movement in the build. The character also doesn't seem to always stay within the bounds of the tiles and weaves just as it did in the editor, only much slower.

https://youtu.be/6RyJNPqkNq4 and here's an example of the the weaving the player does in the editor.

The character also glides from position to position without stop when holding the button down. And when checking the completed project today, the character seems to stop briefly before going on to the next tile when the button is held down. This behavior seems somewhat random, because even with nothing changed, the player will sometimes move normally.

You can see more about the project at http://www.fragmentalstew.com/

This is a demonstration of the game: https://youtu.be/FyUlUlBhzqs

The license of the Roguelike tutorial prevents me from redistributing the project, but I may be able to give you access to to the project if you message or email me.

Here is a link to download the debug build

Comment
Add comment · Show 1
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 Fragmental · Apr 20, 2017 at 10:22 AM 0
Share

So....this bug is back, but in a much later version, after I've made a lot of changes. Except this time the fix I did previously doesn't work. Additionally, character movement seems fine in the editor, only not in the build. :/

6 Replies

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

Answer by Fragmental · Nov 12, 2015 at 12:24 AM

So, I was trying to figure out what was wrong with the completed folder in my project, because it wasn't working right. I had changed the name of a script and made a few changes, then copied the original script back but forgot to change a reference. So I changed the reference, and the completed scene still had issues with movement. So I tried copying an unaltered version of the completed folder over, and every time I did, that reference reset itself, which made no sense since the prefab with the reference was coming from the completed folder I was copying over.

I have a question about it here: http://answers.unity3d.com/questions/1096799/copying-assets-from-one-project-to-another-creates.html

This made me think there could be something wrong with my project. I've been working on the project for 6 months or more and in that time I've had some computer crashes and unity crashes and other issues. So I exported my modified version, copied over the TagManager.Asset file, created a new project and then imported it in. This seems to have fixed the movement issue!

I have no idea what the cause was or if there was any other way to fix it. It may have even had something to do with the Unity upgrades I installed since I started. I have no idea. Either way it seems to be working now. After the export, there was a problem with lines across the board map but it seems to have resolved itself on its own.

Thanks @o-super, you helped me find a solution to this. At first I thought it had something to do with the massive changes I had made in the project, but we both seemed to experience the same issue. I think it was just some sort of buggy weirdness.

Comment
Add comment · Show 2 · 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 o-super · Nov 12, 2015 at 02:11 AM 1
Share

Awesome, I'm glad you did solve the problem. $$anonymous$$eep going on unity, the community seems to be great.

avatar image Seoz · Nov 22, 2016 at 08:54 PM 0
Share

I just wanted to say thank you :) I've got exactly the same error (your video made me sure that its not only me :) ) I checked all code in project without success.. Then I found this answer and it worked! :D

avatar image
1

Answer by o-super · Nov 11, 2015 at 01:20 AM

Hello FragMental,

I had the exact same issue tonight while reaching the step 11 of the tutorial. I tried to build the game for windows and my unity stoped working. I killed the process and launched a new instance of unity.

The only loss I had in the process was my "Main Camera" parameters and the Player who disapeared from my hierarchy. I linked back my GameManager prefabs to the Main Camera and put my Player prebad in the hierarchi and here we go, problem solved.

The only one advise I could give you is to try to create a new scene, remake the steps I did and try.

Comment
Add comment · Show 4 · 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 Fragmental · Nov 11, 2015 at 03:57 AM 0
Share

Your characters in the game were moving slowly? Your player was weaving and not staying inside the tiles?

Building works fine for me, it's just the performance after the game is built that is an issue. There are a few issues with movement even in the editor, however.

I have a lot of UI and code additions so redoing the whole thing would be a big ordeal. Any one of the videos will show you what it looks like. You did give me an idea though. I wonder if I could prefab my UI elements and then import them back into a new scene to skip a lot of the work. Then I could rebuild the scene and see if it still has the same performance issues. That's still a lot of work, even if I can do that. I don't know if will, but it might be worth a try, since I'm currently completely stuck.

avatar image o-super Fragmental · Nov 11, 2015 at 02:36 PM 1
Share

Hey back,

Yes my characters were moving slowly and the player was weaving and not staying inside the tiles. The entire application was running slow and because of this I could move my player before the end of his previous move causing the player to end on a bad location.

In fact I reproduced this problem multiple times, it always happens when I test the game in the Unity IDE after recovering my windows session from a SLEEP mode.

To be clear, If I turn off my PC in sleep mode with Unity open, the next time I turn on my PC I will have to close my Unity and start a new one to make it work properly.

avatar image o-super Fragmental · Nov 12, 2015 at 01:04 AM 1
Share

Another thing, I did another mistake that could be related to the problem (not sure). I'm sharing this just in case, it might help.

$$anonymous$$y game was instanciating multiple scenes at the same time causing the slow effect. To be sure you're not instanciating multiple scenes make sure you did remove the Game $$anonymous$$anager fromyour Hierarchy (sometimes hidden under $$anonymous$$ain Camera) and that your game manager prefab is attached to your Loader script in the main camera.

Lemme know, I really want you to go threw that problem.

avatar image Fragmental o-super · Nov 12, 2015 at 04:12 AM 0
Share

That would be a good reason for issues.

No gamemanager object in my scene here. Just the loader script. I did notice something different about the completed scene and my scene though. The completed scene loads the soundmanager in the loader script, and my soundmanager is in the scene. I don't think it really matters either way for the soundmanager though.

avatar image
1

Answer by Sasune_Fair · Sep 22, 2019 at 04:42 AM

Hey everyone,


I know it's been years but I thought I'd leave my experiences here for any future dwellers.


Basically I had a similar issue as stated by @Fragmental where my character would move super slowly (about 3 seconds per step), and if I input move commands while moving, the character would then do the aforementioned "weaving".


I downloaded a run time Log Viewer by Dream Makers Group to dive into what was really going on.


So basically what I found was that the game was running at 600 fps. It was running at 600 fps as a result of selecting the build option 'Fastest' when building the game. Not sure why that happens though. Anyway, setting the build options to 'Beautiful' made the game run at 60fps, and then everything worked fine.


The reason why things didn't work as well at 600 fps can be described by the following post: https://answers.unity.com/questions/10993/whats-the-difference-between-update-and-fixedupdat.html?_ga=2.82499414.1351522315.1569119747-984558385.1533734503


If you ever stumble across this, do try this solution :) And go Unity! You guys rock.

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
1

Answer by DavidPfeiffer54 · May 26, 2020 at 04:15 PM

I am encountering the same problem in the editor even when running the fresh out the box "completed project". (like stated above, when built/ran it seems to run fine)


I believe rb2D.MovePosition(newPostion) in the SmoothMovement function in MovingObject seems to be the problem. The position doesnt seem to be updated every time SmoothMovement is called. based on the docs, it says that the 'actual position change will only occur during the next physics update'. Is it possible that the physics update isnt happening every call when ran in the editor?


I fixed this by changing

 rb2D.MovePosition(newPostion);

to

 rb2D.transform.position=newPostion;
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 Fragmental · May 28, 2020 at 05:50 AM 0
Share

This sounds really promising for a permanent fix, but if this was the problem all along, I don't know why moving it to a new project would have fixed it for me, or why limiting the fps fixed it for someone else.

avatar image
1

Answer by dshaw002 · Jan 05 at 06:03 AM

The cause of the problem is the FPS going too high during the build. To fix it, create a new script called TargetFrameRate and attach it to your GameManager prefab:

TargetFrameRate.cs

 using UnityEngine;
 using System.Collections;
 
 public class TargetFrameRate : MonoBehaviour {
     
     public int target = 60;
     
     void Start()
     {
         QualitySettings.vSyncCount = 0;
     }
 
     void Update()
     {
         if (target != Application.targetFrameRate)
         {
             Application.targetFrameRate = target;
         }
     }
 }


This will basically force the application into 60fps, resulting in smooth scrolling. Hopefully this can be marked as the correct answer @Fragmental.

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
  • 1
  • 2
  • ›

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

11 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

Related Questions

How to check if mouse is above or below player? 2 Answers

How do I make my character move on the Z axis on 2d rigidbody? 0 Answers

2D movement with transform.translate and collision detection...? 1 Answer

Instantiate after setting values? 0 Answers

How do I get character to always face mouse? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges