Author Topic: Issue with Third Person Controller I just cant figure out  (Read 8382 times)

Talancer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Issue with Third Person Controller I just cant figure out
« on: September 07, 2015, 01:41:25 PM »
Hello All...
I have a problem...well many...but lets just stick to gaming... :P
Anyway...I have been pulling my hair out over this one. I am just starting with TNet and I am 1/2 way following the tutorials as I change a bit here and there to meet my needs. This time however no matter what I do I seem to get this 1 error over and over.

NullReferenceException: Object reference not set to an instance of an object
UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter.CheckGroundStatus () (at Assets/Standard Assets/Characters/ThirdPersonCharacter/Scripts/ThirdPersonCharacter.cs:215)
UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter.Move (Vector3 move, Boolean crouch, Boolean jump) (at Assets/Standard Assets/Characters/ThirdPersonCharacter/Scripts/ThirdPersonCharacter.cs:54)
UnityStandardAssets.Characters.ThirdPerson.ThirdPersonUserControl.FixedUpdate () (at Assets/Standard Assets/Characters/ThirdPersonCharacter/Scripts/ThirdPersonUserControl.cs:71)

I have the TNAutoCreate script creating my player. The player has a Third Person Controller...the default Unity one in the Animator. It has the Third Person Character script, and the Third Person User Control script in the prefab player. The camera and a camerabot is also in there (CameraBot is a nifty little camera control)

If I put the player in the scene, then there are no problems. When I instantiate them...BOING...POW...POP...ugh.... :'(

Again put them in via my own script or the TN Auto Create...the prefab has the TN Object on it...there is also a TN Manager too in the scene, not on the prefab. Even added a GamePlayer script which is an exact copy of the tutorial.

Really I am hoping someone can tell me something here. I have looked all over. There must be something I am not doing correctly. It may be a Unity issue (Or a user issue) and not TN...I kinda doubt it is TN but I am hopeful someone has come across this issue in the past and can say "Oh yeah you didn't do this...." or something.

Talancer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Issue with Third Person Controller I just cant figure out
« Reply #1 on: September 07, 2015, 03:10:15 PM »
Hello again everyone!  :o

I seem to have solved this issue and think I understand why it was occurring.

Well okay...no I have no idea why....

How can a script on an object run before there is the object it is on? Anyone...Anyone???

So by moving the following code to look like it is...moving the Start code to the Awake it seems to have fixed the problem. I also added a reference to the object that the script is on, just to make sure. It might be unnecessary but...this has driven me batty. I wanted to put it out there for anyone else who might have this issue.

      GameObject go;

      void Awake()
      {
         go = this.gameObject;
         
         m_Animator = go.GetComponent<Animator>();
         m_Rigidbody = go.GetComponent<Rigidbody>();
         m_Capsule = go.GetComponent<CapsuleCollider>();
         m_CapsuleHeight = m_Capsule.height;
         m_CapsuleCenter = m_Capsule.center;
         
         m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
         m_OrigGroundCheckDistance = m_GroundCheckDistance;
      }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issue with Third Person Controller I just cant figure out
« Reply #2 on: September 13, 2015, 06:23:27 AM »
All cached values should be set in Awake() anyway. The issue was in that non-TNet script, so I wouldn't have been able to suggest anything other than debugging that code and add a null check.

Most common occurrence of something running before it should is you leaving a prefab in your scene and forgetting to delete it. I've done it many times myself... make a nice prefab, testing it in the scene, then forget it's there. Then when I run the game, the prefab is already there at start instead of when it should be getting instantiated, and I get weird results.