- Home /
Player suddenly disappears!
Hi to everyone. I apologize since now for my english. I'm making a 2D arcade shoot-em-'up game, in which you control a spaceship that has to destroy other ones. On a day, a problem has appeared in my project: The spaceship will be suddenly destroied during game execution, disappearing from the scene (I'm saying "destroied" because, if I pause the game and return to the scene view, the spaceship is no more on the scene - and that's definitely not a rendering problem). I noticed two things:
1) My Unity, during the period in which the problem appeared, crashed. As a consequence, "Player" prefab, that's the spaceship, lost its "box"-icon, and I had to re-imported it. After that, however, the icon reappeared, and that's no track of damaged data.
2) The spaceship (generally) disappears when an object never seen before is rendered on the scene (example: an enemy type appearing in the game for the first time). The game has a little framerate loss (I'm speaking about an half second duration) and, when the framerate turns back to normal, the spaceship is no more on the scene. If i replay the game, the situation seems going better, with the ship that remains on the scene, until the next "new" object rendered (but, I repeat, it's possible that the player disappears also during a "calm" situation, even with a lower probability)
Nobody encountered a similar problem before? Thanks to all for the reading, I apoligize for the topic lenght and I hope to have reported sufficient informations.
Andrea
Don't apologize for your english! You are more polite that 90% of the internet. Reading your question just made my day!
Answer by BiG · Feb 07, 2012 at 05:43 PM
Sorry for bumping this after months, but I've finally found the error that I've done!
Well...I'm feeling like a total noob...I simply attached a TrailRenderer to my spaceship, and this had the Autodestruct parameter activated (I misunderstood the real meaning of that parameter, when I've began this project...)
Thanks again at who partecipated in this thread (that, maybe, could have been interested in my stupid error)!
Answer by aldonaletto · Aug 27, 2011 at 01:20 AM
Take a look at the Hierarchy panel: if the player gets destroyed, it disappears from the Hierarchy list. Sometimes we think some object disappeared, but it has just changed position due to some bug in our scripts. Click the player before run, and it will appear in the Inspector during all the game - this way you can see its Position field and know if something changes the player position.
I read your scripts, and there's nothing there that could destroy your spaceship - except the OnCollisionEnter event, but it should instantiate an explosion, as you've said.
I suspect the problem isn't here, but in other script somewhere in your project - probably an enemy's script. You can use some debug messages to help finding the error; modify the 4th script like this:
function OnDestroy(){ // show the location where the spaceship was destroyed print("Ship destroyed at "+transform.position.ToString()); }
var explosionEffect : Transform;
function OnCollisionEnter (theCollision : Collision) {
if (theCollision.gameObject.tag=="Finish"){ Instantiate(explosionEffect, transform.position, transform.rotation); Destroy(gameObject); // identify the object which destroyed the spaceship print("Ship destroyed by "+theCollision.gameObject.name); } } If the spaceship is being destroyed by the Destroy command, the first message will be displayed, showing the position where it happened. If it was destroyed by an enemy (but the explosion isn't being instantiated for some mysterious reason) the second message will be displayed too - and showing the culprit name. But if the spaceship just disappears and no message is displayed, then you can be a victim of some new Unity bug.
Thank you very much, Aldo. I've followed your advice and the debug prints the first message. So, the spaceship is destroied by "something", but I can't figure out what it is. I'll do other experiments in according with the other objects on the scene (the project has became a bit large, indeed...Other debug has to be done somewhere!) and, if I will discover the cause, I'll let you know. Your help since now has been very appreciated.
Try to find the word "Destroy" in all scripts in your project (use Windows Search or the $$anonymous$$ac equivalent). Pay attention specially to OnCollision/OnTrigger events: a commom mistake is to do something like "Destroy(gameObject)" ins$$anonymous$$d of "Destroy(other.gameObject)"
Answer by BiG · Aug 27, 2011 at 09:37 AM
Thank you for the answer. However, I've already tried what you said (I was not precise in my description last time, sorry): I pause the game, turn back to Hierarchy panel, and "Player" is no more in the list (letting me deduce that's destroied).
I report the script attached to the Player, maybe they could help in understanding the problem:
1) This script let the spaceship shooting, in according to its firepower level:
var newObject : Transform;
function Update () {
firepower= GetComponent(KillPlayer).firepower;
var pos : Vector3 = transform.position;
if (Input.GetButtonDown("Jump") && firepower==1) {
Instantiate(newObject, Vector3(pos.x-4,pos.y,pos.z),transform.rotation);
}else if (Input.GetButtonDown("Jump") && firepower==2) {
Instantiate(newObject, Vector3(pos.x-4,pos.y,pos.z-1), transform.rotation);
Instantiate(newObject, Vector3(pos.x-4,pos.y,pos.z+1), transform.rotation);
}else if (Input.GetButtonDown("Jump") && firepower==3) {
Instantiate(newObject, Vector3(pos.x-4,pos.y,pos.z-1), transform.rotation);
Instantiate(newObject, Vector3(pos.x-4,pos.y,pos.z), transform.rotation);
Instantiate(newObject, Vector3(pos.x-4,pos.y,pos.z+1), transform.rotation);
}else if (Input.GetButtonDown("Jump") && firepower>=4) {
Instantiate(newObject, Vector3(pos.x-4,pos.y,pos.z-1), transform.rotation);
Instantiate(newObject, Vector3(pos.x-4,pos.y,pos.z), transform.rotation);
Instantiate(newObject, Vector3(pos.x-4,pos.y,pos.z+1), transform.rotation);
Instantiate(newObject, Vector3(pos.x-10,pos.y,pos.z-0.5), transform.rotation);
Instantiate(newObject, Vector3(pos.x-10,pos.y,pos.z+0.5), transform.rotation);
}}
2)This one let the ship move vertically during time (because it's an arcade) and avoids that ship exits from the screen (only from left and right, for now):
var speed=5.0;
function Update () {
var y=Time.deltaTime*speed;
transform.Translate(0,y,0);
var pos : Vector3 = transform.position;
if (pos.z>27) //avoid hiding outside the FOV
transform.Translate(-1, 0, 0);
else if (pos.z<-27)
transform.Translate(1, 0, 0);
}
3) This make the ship controllable by arrow keys:
var speed = 20.0;
function Update () {
var x = Input.GetAxis("Horizontal") Time.deltaTime speed; var y = Input.GetAxis("Vertical") Time.deltaTime speed; transform.Translate(x, y, 0);
}
4) And, at last, the control about player's distruction (no respawn for now) - ("Finish" tag is obviosly attached to enemies):
var explosionEffect : Transform;
function OnCollisionEnter (theCollision : Collision) {
if (theCollision.gameObject.tag=="Finish"){ Instantiate(explosionEffect, transform.position, transform.rotation); Destroy(gameObject); } }
It seems to me that anything in the scripts could create such problem (moreover, the only destruction allowed by last script is in conjunction with an explosion, so I also excluded a "not-considered-case" about it, since the explosion doesn't take place when the ship disappears).
Thank you in advice, hope that someone could have other ideas.
Answer by jimmyismike · Aug 27, 2011 at 10:58 AM
I think I may know the problem happened to me. Does the spaceship shoot? Does the spaceship have a life bar attached to it? Cause sometimes what happens is that you shoot your self. So move the Empty Gameobject or what every is shooting a bit away from the spaceship.
Thanks a lot, jimmyismike, but, certainly, that's not the problem, because I've just considered that case: in the first script, I've generated the projectiles at pos.x-4: That "-4" avoid the ship to kill herself.
Your answer
Follow this Question
Related Questions
Make enemy appear in front of player and then disappear at random times 2 Answers
The player disappears in the air 1 Answer
Make smoke fade away when player passes through 1 Answer
Need a "ghost" script ! 1 Answer
ai to input value 0 Answers