Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by strudi1986 · Oct 17, 2017 at 08:15 PM · cameramultiplayernullreferenceexception

Multiplayer Player Prefab: NullReferenceException: Object reference not set to an instance of an object

Hi!

I have a problem! I want to test multiplayer a little bit so i set up a scene with network manager and the network identity on the player prefab! i dragged the player prefab in the slot in the network manager! the camera control is seperatly and not connected with the player prefab! offline everything works ok, but when i start the multiplayer test i get the following NullReferenceException:

NullReferenceException: Object reference not set to an instance of an object CameraOrbit.Start () (at Assets/Scripts/Camera Scripts/CameraOrbit.cs:29)

NullReferenceException: Object reference not set to an instance of an object CameraOrbit.HandleCamera () (at Assets/Scripts/Camera Scripts/CameraOrbit.cs:64) CameraOrbit.Update () (at Assets/Scripts/Camera Scripts/CameraOrbit.cs:45)

Player Movement is working correctly but the camera wont. ive tried several things now but i cant find the right solution. the error occurs in the camera script.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CameraOrbit : Orbit {
 
     public Vector3 targetOffset = new Vector3 (0, 2, 0);
     public Vector3 cameraPositionZoom = new Vector3 (-0.5f, 0, 0);
     public float cameraLenght = -10f;
     public float cameraLenghtZoom = -5f;
     public Vector2 orbitSpeed = new Vector2 (0.01f, 0.01f);
     public Vector2 orbitOffset = new Vector2 (0, -0.8f);
     public Vector2 angleOffset = new Vector2 (0, -0.25f);
 
     private float _zoomValue;
     private Vector3 _cameraPositionTemp;
     private Vector3 _cameraPosition;
 
     private Transform _playerTarget;
     private Camera _mainCamera;
 
     void Awake ()
     {
         
     }
 
     // Use this for initialization
     void Start () {
             _playerTarget = GameObject.FindGameObjectWithTag ("Player").transform;
 
             sphericalVectorData.Lenght = cameraLenght;
             sphericalVectorData.Azimuth = angleOffset.x;
             sphericalVectorData.Zenith = angleOffset.y;
 
             _mainCamera = Camera.main;
 
             _cameraPositionTemp = _mainCamera.transform.localPosition;
             _cameraPosition = _cameraPositionTemp;
 
     }
     
     // Update is called once per frame
     void Update () {
 
         HandleCamera ();
     }
 
     void HandleCamera ()
     {
         if ( Input.GetMouseButton (1) )
         {
             sphericalVectorData.Azimuth += Input.GetAxis ("Mouse X") * orbitSpeed.x;
             sphericalVectorData.Zenith += Input.GetAxis ("Mouse Y") * orbitSpeed.y;
 
             sphericalVectorData.Zenith = Mathf.Clamp (sphericalVectorData.Zenith + orbitOffset.x, orbitOffset.y, 0f);
         }
 
             float distanceToObject = _zoomValue;
             float deltaDistance = Mathf.Clamp (_zoomValue, distanceToObject, -distanceToObject);
             sphericalVectorData.Lenght += (deltaDistance - sphericalVectorData.Lenght);
 
             Vector3 lookAt = targetOffset;
 
             lookAt += _playerTarget.position;
 
             base.Update ();
 
             transform.position += lookAt;
             transform.LookAt (lookAt);
 
             if ( _zoomValue == cameraLenghtZoom )
             {
                 Quaternion targetRotation = transform.rotation;
                 targetRotation.x = 0f;
                 targetRotation.z = 0f;
                 _playerTarget.rotation = targetRotation;
             }
 
             _cameraPosition = _cameraPositionTemp;
             _zoomValue = cameraLenght;
     }
 }
 

ive tried to set the _playerTarget variable public and i saw that this variable stays empty after start. i think thats the problem. can anyone help? Thank you

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

153 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Null reference exception on Screenpointtoray (Multiplayer) 1 Answer

How to have player camera Render enemy but not itself with same tag and camera clipping mask? 0 Answers

How do I make a Game Object invisible? 1 Answer

How do you use a camera from another scene on your skybox? 1 Answer

Camera Board Game - Multiplayer,Multiplayer camera - best practice 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges