Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Sep 27, 2015 at 01:12 PM by RedDevil for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by RedDevil · Jul 07, 2014 at 09:26 AM · errorcontrollerasset

Sample Assets Third person Controller Error

I am using the Third Person Controller script from the Sample Assets on a instantiated player object and I keep getting these errors that I dont realy know how to solve. Please Help me!

  void PreventStandingInLowHeadroom ()
 {
     // prevent standing up in crouch-only zones
     if (!crouchInput) {
         Ray crouchRay = new Ray (rigidbody.position + Vector3.up * capsule.radius * half, Vector3.up);
         float crouchRayLength = originalHeight - capsule.radius * half;
         if (Physics.SphereCast (crouchRay, capsule.radius * half, crouchRayLength)) {
             crouchInput = true;
         }
     }
 }    

The error is on the Ray crouchRay row and it says :NullReferenceException: Object reference not set to an instance of an object.

alt text I am not quite sure what reference I am suposed to set...

inspector.png (52.6 kB)
Comment
Add comment · Show 12
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
avatar image HarshadK · Jul 07, 2014 at 09:37 AM 0
Share

Does your player game object has a rigidbody component attached to it?

avatar image RedDevil · Jul 07, 2014 at 09:38 AM 0
Share

yes it does

avatar image HarshadK · Jul 07, 2014 at 09:42 AM 0
Share

You have a reference stored for CapsuleCollider in your capsule variable?

avatar image RedDevil · Jul 07, 2014 at 09:47 AM 0
Share

added a picture with what i have in the inspector. Do you think the problem is with the capsule collider because it has no physic material?

avatar image HarshadK · Jul 07, 2014 at 09:52 AM 0
Share

I don't think physics material is an issue.

Just to confirm, you have a reference stored for CapsuleCollider in your capsule variable and it is accessible in your current script?

Show more comments

1 Reply

  • Sort: 
avatar image
0

Answer by WhoRainZone1 · Jul 07, 2014 at 05:40 PM

Heho,

you need to add an "out hit" in C#.

         void PreventStandingInLowHeadroom ()
         {
         // prevent standing up in crouch-only zones
         if (!crouchInput) {
         Ray crouchRay = new Ray (rigidbody.position + Vector3.up * capsule.radius * half, Vector3.up);
 RaycastHit hit;
         float crouchRayLength = originalHeight - capsule.radius * half;
         if (Physics.SphereCast (crouchRay, capsule.radius * half, out hit, crouchRayLength)) {
         crouchInput = true;
         }
         }
         } 
 

Not tested, but that should be the issue

edit:

If you then want to access the raycast hit, use hit.transform.position for positions and hit.collider.name == gameObject.name to detect if you clicked a specific object.

Cheers, wrz

Comment
Add comment · Show 1 · Share
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
avatar image RedDevil · Jul 07, 2014 at 06:14 PM 0
Share

looking closer to the full error: NullReferenceException: Object reference not set to an instance of an object SorcererThirdPersonController.PreventStandingInLowHeadroom () (at Assets/Scripts/SorcererThirdPersonController.cs:152) SorcererThirdPersonController.$$anonymous$$ove (Vector3 move, Boolean crouch, Boolean jump, Vector3 lookPos) (at Assets/Scripts/SorcererThirdPersonController.cs:98) ThirdPersonUserControl.FixedUpdate () (at Assets/Imports/Sample Assets/Characters/Third Person Character/Scripts/ThirdPersonUserControl.cs:80) I think the problem after all is in another script on ThirdPersonUserControl. here is the code from there:

// pass all parameters to the character control script

character.$$anonymous$$ove( move, crouch, jump, lookPos );

Follow this Question

Answers Answers and Comments

24 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

Related Questions

All Charater controllers not working, (Same issue). 0 Answers

Texture/Materials are not loading ,Textures are not showing up on my materials 0 Answers

help with network controling 1 Answer

Errors with Simple Inventory free Asset 1 Answer

can someone look at my script 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