I have a fairly simple hockey game that I’ve created and intend to showcase at an event this Thursday. Unfortunately I sometimes get the following error message and the game freezes.
I don’t know how to recreate the problem consistantly.
From what I’ve read, this is an internal Unity problem but I need this demo to work and not freeze when I have a group of people watching or playing it.
Does anyone know what part of a game this error message would be reponding to? I could always rework the code or assets to avoid the problem.
The game plays fine for anywhere from 1 minute to 20 minutes and then the ice disappears and the movement stops and that error message comes up at the bottom. I have never had a freeze that wasn’t accompanied by that error message.
The game is free standing in that it all takes place at one time in one window. Whatever you can do in the first few seconds, you can do for the rest of the game without anything new being introduced.
The game has 7 inputs.
2 for passing left and right
2 for shooting on goal
2 for starting and stopping defensemen on animated movement path
1 for starting and stopping a goalie on an animated movement path
The only other element, besides the static ice, walls and net object, is a looping organ track.
I have tried for over on hour to recreate the problem with keystrokes but I haven’t been able to consistently reproduce the error.
Following your thought above in light of Joachim’s comments, have you verified that at the point the freeze occurs that you’re not locked in a never-ending loop somehow?
Is playerposition ever not 1-5? since you’re using else if statements one of those conditions have to be true. If you switched it to regular if statements or a switch (does Javascript have those?) and set the default to do nothing then you may not have a problem.
I guess the error could also be in the Update function and the if - else if statements there. But it seems more likely to be the other.
No; using 0 or 0.00 normally makes no difference. The only time it would matter is when defining a variable…if you use 0, the variable is defined as an integer (unless you specifically say otherwise), and using 0.0 makes it a float.
I don’t think I see anything there that would cause a freeze. A couple of hints that would save some typing, though: statements like “playerposition = playerposition + 1;” can be better written as “playerposition += 1;”, or in the case of simple incrementing like that, “playerposition++;” (and “playerposition–;” for decrementing). You also might find using the switch/case construct (yes, Javascript has that) more convenient than a series of if/if else statements.
Thanks for the tips. I’m a self taugh (much assisted) programer with a minor REALbasic background so I never really learned all of the time saving options.
I updated the script and removed the elses and changed the == to < and > to keep my values in range but it still eventually freezes.
I got distracted while testing the game and when I came back the ice had disappeared but the game had not frozen. None of my code mentions the ice so I have no idea why this happened.
I’m going to give the scoring system a closer look but I doubt that that is the problem as I have used those scripts in other games.
I’ve added a screen shot of the game in working mode so you can get and idea of how the game works.
Given that the script you cited doesn’t contain any loops, why is it that you think that one in particular might cause problems? Was it just the =0 versus =0.0 that struck you as a possible issue? (as mentioned above that’s not a problem) After giving it a quick scan I too fail to see anything obviously wrong with the script and I’m a bit stuck as to what your next steps ought to be. Perhaps a brute force approach is needed here, put a bunch of Debug.Log() statements in your code or something, that way when you run the game and it freezes you’ll have an idea as to what code is executing when the freeze occurs.
Are you doing anything with OnCollision* or OnTrigger* where you might also move one of the objects involved in the collision/trigger? There is a way that this can cause an infinite loop that takes down Unity. For example, if in OnTrigger() you are moving one of the objects to a specific location, then that move could trigger an OnTrigger() that will then move the object back to that position, which will … You get the idea. Not that I know anything personally about this scenario
I have had some other situation where Unity appears to go down for no reason, but unfortunately I cannot think of them right now Pay extra attention anyplace where you are interacting with the physics engine but are making modifications that the physics engine will take into account.
var score : ScoreGoalie;
function OnCollisionEnter (col : Collision) {
if (col.other.gameObject.CompareTag ("Puck")) {
if (audio !audio.isPlaying) {
audio.Play ();
}
score.AddToScore ();
}
}
The next scrpt starts and stops the opposing players. Any concerns with it?
var curnum = 1;
var stoptime = .5;
private var nextshot = 0.0;
function Update () {
if (Input.GetAxis ("Defender2") Time.time > nextshot) {
nextshot = Time.time + stoptime;
if (curnum == 2){
animation["Default"].speed = 1;
curnum = 1;
}
else if (curnum == 1){
animation["Default"].speed = 0;
curnum = 2;
}
}
}
That’s pretty much it for the game besides the scoring.
Is it possible that the mesh for the ice object (the ice disappears just before a freeze) is some how doing the damage? It’s just a simple plane but I could exchange it.
just a crazy idea… sounds like this is all in editor? have you built a standalone to see if the same thing happens? maybe something got messed in your unity install or there’s something in the project but not in the game that unity doesn’t like.
Not that the functionality will change or anything. Sorry…I’m not trying to be annoying.
The ice thing is weird…obviously that shouldn’t happen. What properties does it have? The only thing I can think of is that it’s being affected by physics somehow in some way that it shouldn’t.
but you dont do that for c d, seems like you should initialize them in the same way. Not initializing the rotation could cause the assert you were getting.
Also i would move that initialization code into the Start function instead of global scope for clarity.
How about removing the rigidbody on the ice altogether? You have Is Kinematic checked, so it doesn’t seem like it would make a difference, but you shouldn’t need the rigidbody for anything in that case (just the collider), so give it a try.
A bit of new info. While I was running a recent test. The ice eventually disappeared but the game continued. It froze when I hit the shoot puck key. The script I use for shooting the puck is based on the one from the original unity demo scene so I doubt it would be causing the error but here it is.
var ball : Rigidbody;
var velocity = 30.0;
var fireRate = 1.0;
private var nextFire = 0.0;
function Update (){
if (Input.GetAxis ("Shoot1") Time.time > nextFire) {
nextFire = Time.time + fireRate;
var shoot : Rigidbody = Instantiate (ball, transform.position, transform.rotation);
shoot.velocity = transform.rotation * Vector3.fwd * velocity;
}
}
Thanks for everyones continued help. I’m showing this game at a Innovation’s Expo tomorrow so I really hope I can solve the problem. For clarification I know that this game isn’t ground breaking. I have been developing the game with a group of people with disabilities and we are looking at making it available to others. They love hockey and they love the game (until it freezes).