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
1
Question by Lechitsune · Apr 11, 2018 at 08:04 AM · scripting problemnullreferenceexceptionontriggerentercomponent

Trigger reference problem

alt text My bus goes to trigger and I get null reference exception problem on this script.

I want a move passenger in trigger enter.

So how I do this ?

*alt text

screenshot-5.png (7.1 kB)
screenshot-6.png (459.0 kB)
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

1 Reply

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

Answer by tormentoarmagedoom · Apr 11, 2018 at 08:14 AM

Good day.

I was writing your answer in the last post, but you changed it and now have to write all again... :(


null reference exception means there is a variable that is not assigned when trying to execute that line. So if the problem is in the image line, most probably the boject containing this script, does not have the component passangermove so when try to find it gives you the error. You see you are not looking for the PAssangerMove in the bus right? you are looking inside the same GameObject that contains this script. To acces the bus you need:

 other.GetComponent<PassangerMove>().....

A good practice is to use

 Debug.Log(SomeVariable);

just the line before of the problematic line to see whats the state of the variable.


Other important thing. Is NOT a good practice to enable/disable scripts. Is beter to have the script always enabled, and change some variable when needed (like a bool) to allow the script do something.


If helped, accept the answer! If need more help, give more info!

Comment
Add comment · Show 4 · 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 Lechitsune · Apr 11, 2018 at 08:41 AM 0
Share

thanks for message but my problem doest not fixed. :(

http://sendvid.com/7xjggzkk

avatar image tormentoarmagedoom Lechitsune · Apr 11, 2018 at 08:48 AM 0
Share

As I said, you first need to detect which variable is not assigned when trying to execute.

And then discover why is not assigned. We can assume the OnTriggerEnter is executing, right? so the problem must be inside. With the info you gave, we can not help more. Give more info, paste all error text.

avatar image Lechitsune · Apr 12, 2018 at 07:20 AM 0
Share

thanks you for help <3 I fix it :)

avatar image tormentoarmagedoom Lechitsune · Apr 12, 2018 at 08:01 AM 0
Share

for curiosity, what was null?

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

140 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

Related Questions

Object not responding to OnTriggerEnter() 2 Answers

2D Animation does not start 1 Answer

Button interactable not working via script 1 Answer

Enabling multiple Monobehaviour Components in a game object 1 Answer

enable and disable script on Unity gameobject 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