D
D
Dislokaynt2016-08-28 11:19:27
Unity
Dislokaynt, 2016-08-28 11:19:27

Where did NullReferenceExeption come from?

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

    public float Speed = 6f;

    Vector3 _movement;
    Animator _anim;
    Rigidbody _playerRigidBody;
    int _floorMask;
    float CamRayLength = 100f;
    void Start()
    {
        _floorMask = LayerMask.GetMask("Floor");
        _anim = GetComponent<Animator>();
        _playerRigidBody = GetComponent<Rigidbody>();
    }
    void FixedUpdate()
    {
        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");
        Move(h, v);
        Turning();
    }
    void Move(float h, float v)
    {
        _movement.Set(h, 0f, v);
        _movement = _movement.normalized * Speed * Time.deltaTime;
        _playerRigidBody.MovePosition(transform.position + _movement);
    }
    void Turning()
    {
        Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit floorHit;
        if (Physics.Raycast(camRay, out floorHit, CamRayLength, _floorMask))
        {

            Vector3 playerToMouse = floorHit.point - transform.position;
            playerToMouse.y = 0;
            Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
            _playerRigidBody.MoveRotation(newRotation);
        }

    }
  // Update is called once per frame
  void Update () {
  
  }
}

And here is the error itself:
NullReferenceException: (null)
UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs) (at C:/buildslave/unity/build/artifacts/generated/common/editor/SerializedPropertyBindings.gen.cs:74 )
UnityEditor.AssetImporterInspector.GetSerializedObjectInternal () (at C:/buildslave/unity/build/Editor/Mono/ImportSettings/AssetImporterInspector.cs:57)
UnityEditor.Editor.get_serializedObject () (at C:/buildslave/unity/build/artifacts /generated/common/editor/EditorBindings.gen.cs:147)
UnityEditor.ModelImporterClipEditor.OnEnable () (at C:/buildslave/unity/build/Editor/Mono/ImportSettings/ModelImporterClipEditor.cs:139)
The code is completely working, doing all its functions, and all the necessary objects are present on the player
Or is the error related to the imported player model?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dislokaynt, 2016-08-29
@Dislokaynt

The next day, the error disappeared as unexpectedly as it appeared)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question