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 /
  • Help Room /
avatar image
0
Question by hbarsquared · Dec 03, 2019 at 01:15 PM · nullreferenceexceptiontutorialstandard-assets

NullReferenceException being logged from an inactive script

I'm using the Unity standard asset of a car and running through Jimmy Vegas' racing tutorial. I want to make the CarController script inactive until a countdown finishes. If I deactivate the script in the Inspector window and then try to run my scene, I get the following error:

 NullReferenceException: Object reference not set to an instance of an object
 UnityStandardAssets.Vehicles.Car.CarController.get_CurrentSpeed () (at Assets/Standard Assets/Vehicles/Car/Scripts/CarController.cs:53)
 UnityStandardAssets.Vehicles.Car.CarController.ApplyDrive (Single accel, Single footbrake) (at Assets/Standard Assets/Vehicles/Car/Scripts/CarController.cs:224)
 UnityStandardAssets.Vehicles.Car.CarController.Move (Single steering, Single accel, Single footbrake, Single handbrake) (at Assets/Standard Assets/Vehicles/Car/Scripts/CarController.cs:153)
 UnityStandardAssets.Vehicles.Car.CarUserControl.FixedUpdate () (at Assets/Standard Assets/Vehicles/Car/Scripts/CarUserControl.cs:27)

It seems like if CarController isn't active, it shouldn't even be executing and finding itself to be null, right? Is there a more "proper" way to inactivate a controller script until some condition is true?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by hbarsquared · Dec 05, 2019 at 10:26 AM

I found the issue myself (read the errors, stupid!). The last line of that error references Car.CarUserControl, not Car.CarController. That script is still active, and it references the (inactive) CarController script.

I switched my setup to have CarUserControl inactive instead of CarController, and that solved my problem.

Comment
Add comment · 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
0

Answer by Aindi · Mar 07, 2020 at 06:29 PM

This error is occurring because of the m_rigidbody is returning null. Set the Rigidbody component reference to the m_Rigidbody in the Awake method ( and remove/comment the GetComponent() line in the CarController Start Method). That will resolve the error. Since Awake method is called whether GameObject is active/inactive.

Comment
Add comment · 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
0

Answer by bielzinho_yt · Nov 27, 2020 at 05:35 PM

Pessoal nao sei quem ainda está tendo estes problemas, mais eu tive e resolvi da seguinte forma: notei que meu Carro(Player) tinha varios scripts acoplados em si, cada um com suas funções (ex: destruição, Liga/Desliga, outras funções nas quais vc também incrementou no seu carro), eu desativei todos os scripts do Carro(Player) e deixei apenas os de controles, e fui testando, ao iniciar a gameplay eu ia ligando manual um por um para ver se estava dando interferencia, e descobri que meu script (InputSystem) que faz a ligaçao entre o kayboard e o Touch estava dando interferencia, caso se eu ligasse antes do CarController ele acusava o erro que muitos estavam tendo, então coloquei um tempo de 0.9f de segundos para ligar apos o CarController, e agora está funcionando direitinho, posso até acrescentar mais alguma coisa no script que faz essa ligação de componente que nao da nenhuma interferencia, e também não precisei acrescentar o script padrão do CarUserControl no meu Player que no meu caso não tem utilidade alguma, pode ser que outras versões do unity seja necessária que foi no caso da Unity5 pelo menos eu tive este problema nesta versão, então migrei para a 2018 pois a 2019 não gostei nada da interface preta rsrsrs talvez dava pra mudar e eu nao sabia ksks mais gostei da 2018 e estou usando atualmente até pegar um pc bom e usar a unity 2020, mais enfim esta foi minha experiencia com este erro que ficou me solando durante 2 dias seguidos, era um stress... Mano eu não sei explicar muito bem, mais deixo aqui oque resolveu pra mim ;-) espero que ajude outros...

Comment
Add comment · 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

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

196 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 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

Tanks Tutorial: Accessing TankHealth 1 Answer

NullReferenceException: Object reference not set to an instance of an object, again 2 Answers

Car from Unity's standard assets giving me of null reference errors 0 Answers

Localization Unity Tutorial NullReferenceException 0 Answers

Checkpoints between scenes (NullReferenceException?) 0 Answers


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