Odd Problem with Windows Builds in Unity

Made by Unity Technologies - "Taking the pain out of game development."

Odd Problem with Windows Builds in Unity

Postby GarrettSkye » February 2nd, 2010, 12:42 am

For some reason, my game works as intended in the editor, and if I build a web game it also works perfectly. However, whenever I build a Windows Standalone, it acts as if I have all the wrong values in there, like its using an old variable, instead of the new values I've entered into my scripts. Anyone else having similar trouble? Is this a bug in Unity that I'm unaware of? I've found a few people with the same issue on the official forums, but no fix other than recreating my whole project. While it certainly wouldn't be impossible to do, I'm hoping for a simpler (and more permanent) solution.

Anyone who can give me a good answer will get a free cookie from me at the bake sale :D
James Thompson
GarrettSkye
Archer
Archer
 
Posts: 15
Joined: March 19th, 2008, 5:38 pm

Re: Odd Problem with Windows Builds in Unity

Postby Teriki Tora » February 2nd, 2010, 6:49 am

I've had programs with similar problems. The few solutions that I can think of are these:

  • -Save the file as something else (instead of XXX.Uni name it YYY.Uni)
  • -Copy scripts, paste over existing scripts (basically taking the script you want, and re-pasting it into your scripts, or the starter scripts, making the scripts all over again, not the entire file)
  • The dreaded - Make a new file, copy stuff from old file and paste into new one (This one is annoying to the max, but sometimes it's the final solution)

Usually saving it as a new filename makes the program believe it's a new file, after saving it under the new filename, close the program and open up the new filename file (Not the old one that's been giving you the problems). Afterwords, check your scripts and export as a Windows Stand-alone and see how that works.
Common nicknames from Username: Teri, Tora, Tiger, Kit (from Trikitiger)

Green Bay Campus Rules! X3

http://terikitora.webs.com/ --- My Portfolio
http://www.marriland.com/ --- I'm a Jr. Admin there :3

てり期トラの芸術はかわいい! - 任意日本のおたく
未加工および強力 - 擬似堅い男
User avatar
Teriki Tora
Thief
Thief
 
Posts: 74
Joined: November 11th, 2008, 9:02 am
Location: North of GB

Re: Odd Problem with Windows Builds in Unity

Postby GarrettSkye » March 17th, 2010, 3:09 am

Kind of a late reply, as I fixed this about a day after my original post, but I figured I'd post an update about this problem. What caused this was not a problem with the build, but of course, a stupid error on my part.

Say you have code like this (The following is C# btw, not JavaScript, but the same principles apply):
Code: Select all
void Update() {
  transform.position = new Vector3(transform.position.x, transform.position.y + speed, transform.position.z);
}


What this is going to do is move the GameObject this script is attached to "speed" number of units each frame. This is what was causing my problem. In a web build, the FPS are limited to around 60fps, and everything looked fine. But on beefy systems, the Windows build could reach upwards of 500fps at the time. So instead of moving 60 units each second, it was now moving 500.

What I had to do was the following:
Code: Select all
void Update() {
  transform.position = new Vector3(transform.position.x, transform.position.y + (speed * Time.deltaTime), transform.position.z);
}


What this did is multiply speed times the amount of time between updating the last two frames. By doing this, it is now moving "speed" number of units per second, instead of per frame, thus making the game frame rate independent.

Whats funny about this is that I did exactly this for vertical movement, but not for horizontal. So the ship would move up and down at the right speeds, but would fly abnormally fast when running at high frame rates.

But now our game works properly. :clap:
James Thompson
GarrettSkye
Archer
Archer
 
Posts: 15
Joined: March 19th, 2008, 5:38 pm

Re: Odd Problem with Windows Builds in Unity

Postby SpartanDonut » March 17th, 2010, 2:19 pm

Thanks for the update! This is very insightful. I have actually experienced a similar issue before and solved it in a similar manner.

A lot of engines actually cap how many frames they process per second and put the application to sleep for the remaining time for specifically this reason actually. While it won't completely fix the issue due to differing frame rates, it will help make the differences a lot smaller. Long story short, don't rely on your engine doing this and implement your game play correctly.

Good work at solving your issue. Definitely one of those where if you experience the issue, you probably won't repeat the mistake you made. :mrgreen:
User avatar
SpartanDonut
Wizard
Wizard
 
Posts: 132
Joined: November 13th, 2008, 8:21 pm


Return to Unity

Who is online

Users browsing this forum: No registered users and 1 guest

cron