- Home /
Prolem comes from another Problem with corrupte files
GetComponent NullReferenceException
Hey,
When I build my project and try to connect to or start a server the camera of the player flickers. The player camera jumps from looking straight upward to looking straight forward the entire time which causes it to flicker. When I ran the project in the Editor and connect to or start a server it's totally fine expect that if another player is on the server I get a NullReferenceException in this part of my code:
function OnNetworkInstantiate(){
if(!networkView.isMine){
var tmp5 = transform.gameObject.GetComponent(MouseLook);//<--Error
tmp5.enabled = false;
}
}
This is not the whole script(It's called PlayerScript) I just filtered out the interesting part. I hope it's enough code.
In the MouseLook script I also have this code:
void Start(){
if(!networkView.isMine)
enabled = false;
if (rigidbody)
rigidbody.freezeRotation = true;
}
I also noticed similar problems with GetComponent in other Projects after updating to Unity 4.
I found it weird that these problems started with the Update and I hope someone can help me.
Cheers,
ExTheSea
Answer by DeveshPandey · Nov 26, 2012 at 06:10 AM
Use Generic function. See here
Thank you for your answer. I will try this as soon as I get my Unity to work again. ($$anonymous$$y builds don't work because Unity produces corrupt sharedassets1.assets files).
I will come back to this if I get to try it.