- Home /
Problems with Network.destroy
So in my game my character has a self-destruct feature. With this code:
if(networkView.isMine){
if(Input.GetKeyDown (KeyCode.Mouse0)){
GameObject instantiatedProjectile = (GameObject)Network.Instantiate(sefDestruct, transform.position, transform.rotation,0);
instantiatedProjectile.GetComponent<Detonator>().Explode();
Network.Destroy(this.gameObject);
}
}
my character doesn't dissapear on fire. But if I comment out the two lines spawning the explosion then he does.
//GameObject instantiatedProjectile = (GameObject)Network.Instantiate(sefDestruct, transform.position, transform.rotation,0);
//instantiatedProjectile.GetComponent<Detonator>().Explode();
What gives?
Are there any errors printed out? Sometimes when Unity runs into errors, some undesirable things can happen to the things near the error.
Yeah you are correct. I am getting some null reference errors. I am playing with the Detonator package and they have some prefab examples for me to use. Would you happen to know why when I drag and drop them into my scene they go off without a hitch but if I try to spawn the explosion prefabs, all of the materials are unassigned?
UPDATE: ok, so it's not an issue with materials being un-assigned. I feel the problem lies with the fact that after I spawn an object, I then proceed to destroy the gameobject that created it. Is there some type of object ownership going on that I may need to pass?
Answer by Max12314 · Dec 13, 2013 at 06:14 PM
So I fixed it but I don't understand the reasoning why my fix works. When I destroy myself on the next frame everything seems to work out fine.
Your answer
Follow this Question
Related Questions
Simple activation network script 0 Answers
NetworkReader/Writer with GameObject 0 Answers
[Command] tag not working 0 Answers
Non player objects movements are not syncronized on server 0 Answers
How to synchronize GameObjects 2 Answers