- Home /
Missing Component Exception Error
When I try to run this code, I received a Missing Component Exception. It said "There is no 'NetworkView' attached to the "Player(Clone)" game object, but a script is trying to access it. You probably need to add a NetworkView to the game object "Player(Clone)".
How do I add a NetworkView to the game object "Player(Clone)"?
void spawnPlayer() {
Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0 );
}
void Update(){
if(networkView.isMine){
moveDirection = new Vector3(Input.GetAxis ("Horizontal") * speed * Time.deltaTime, -gravity * Time.deltaTime, Input.GetAxis("Vertical") * speed * Time.deltaTime);
moveDirection = transform.TransformDirection (moveDirection);
chc.Move(moveDirection);
}
I have the Network Manager script attached to the Network Manager game oject within the scene. And I have the Player (Prefab) attached. But when even I start the game, it makes a Player Clone prefab and then gives me this error. I'm stuck can anybody please help me?
Also when I run my game, the Player prefab is created as Player(Clone) and there is no Network View attached to the game object, so it doesn't run.
Answer by cupsster · Jul 18, 2012 at 09:56 AM
Select your object then go to Component > Miscellaneous > Network View This will add required component to your script, or you can use at begining of your script:
[RequireComponent (typeof (NetworkView))]
Answer by Kryptos · Jul 18, 2012 at 10:01 AM
You need to add a Networkview component to your Player prefab.
You can also do it automatically by adding the RequireComponent attribute before the declaration of the class in your script file:
[RequireComponent (typeof(NetworkView))]
public class Player : MonoBehaviour {
}
Answer by senad · Jul 18, 2012 at 09:42 AM
Is there a NetworkView attached to your Player prefab? If not, create a new one and attach it.
Your answer
Follow this Question
Related Questions
Unity 5.0, ambiguous component reference? 1 Answer
Try Catch not working with VideoPlayer 2 Answers
Unity 2017.3 Android IL2CPP ArgumentNullException 2 Answers
Inspector Error 1 Answer