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
0
Question by chrisjacobsz97 · Jun 10, 2018 at 05:56 PM · gameobjectnullreferenceexceptiongetcomponent

GetComponent not working

I have a gameobject called CPJ that has a script (Row Controller) attached to it, which has a method called TransferRow.

alt text

In another gameobjects script i want to call TransferRow and i call it as follows

 public GameObject CRJ;
 public RowController CRJRC;
 
 
 public void Method1()
 {
 CRJ = GameObject.Find("CRJ");
 CRJRC = CRJ.GetComponent<RowController>();
 CRJRC.TransferRow(int.Parse(df.txtDay.text), df.txtDetails.text, df.txtBank.text, df.txtSundryDetails.text, "CPJRow", df.CoinType);
 }

This gives me a nullreferenceException on the line CRJRC.TransferRow(...);

CRJ is called correctly as a simple debug.log confirms.
In the inspector on the gameobject doing the calling, the public variable CRJ is filled correctly, and CRJRC is also present as seen below.

alt text

Im not sure as to why the nullReferenceException occurs and i have tried calling it in other ways, but with no success.

I am not adding the RowController script reference directly to my "Send to other Journal" script via the inspector, as the the object that the script is attached to is important and used in the script.

Please Advise on how i can call this method, or if you see any errors that i have missed. if you need any extra information i will gladly supply it.

TransferRow code

 public void TransferRow(int Day, string Details, string Amount, string SundryDetails, string Journal, string CoinType)
     {GameObject row = Instantiate(OtherBookRow, OtherBookContents).gameObject;}

cpj.jpg (42.1 kB)
crjrow.jpg (29.9 kB)
Comment
Add comment · Show 7
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 bakir-omarov · Jun 10, 2018 at 06:02 PM 0
Share

Can you share CRJRC.TransferRow code. Is it Public Void ?

avatar image chrisjacobsz97 bakir-omarov · Jun 10, 2018 at 06:20 PM 0
Share

yes CRJRC is public void

looks like this

 public void TransferRow(int Day, string Details, string Amount, string SundryDetails, string Journal, string CoinType)
     {GameObject row = Instantiate(OtherBookRow, OtherBookContents).gameObject; }
avatar image bakir-omarov chrisjacobsz97 · Jun 10, 2018 at 06:25 PM 1
Share

Can you change any variable in RowController from SendToOtherJournal ? Try to change any float or int. If it works, then you are not sending all/correct variables to the Void ((int Day, string Details, string Amount, string SundryDetails, string Journal, string CoinType))

Show more comments
avatar image seandolan · Jun 10, 2018 at 06:08 PM 0
Share

What are the ..... marks in CRJRC.TransferRow(.....); They will cause a problem.

avatar image chrisjacobsz97 seandolan · Jun 10, 2018 at 06:17 PM 0
Share

... just replacing the bunch of variables in the call

avatar image chrisjacobsz97 seandolan · Jun 10, 2018 at 06:23 PM 0
Share

I updated the question and added the complete call

1 Reply

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

Answer by chrisjacobsz97 · Jun 10, 2018 at 06:33 PM

Problem Solved

As @bakir-omarov mentioned, i tested to see if i could change a variable and i could.
Checked the call, turns out the variable that holds the values i was sending in the TransferRow call was the problem, and was returning null, and so the values were null

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 seandolan · Jun 10, 2018 at 07:47 PM 0
Share

Glad you fixed it. For next time though it's always easier for us if you include all the code. Then we can help. Partial information means more work for those trying to help you. We probably could have told you what the problem was straight away with all the info. Great job in working it out though man! Happy coding.

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

131 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

Related Questions

Assign collider and linerenderer to list 1 Answer

script GetComponent, nullReference error 1 Answer

NULL REFERENCE EXCEPTION,NULL REFERENCE EXCEPTION while accessing child objects unity2D 0 Answers

Why is this null? Finding a script on an object 3 Answers

Getting errors when referencing a variable. 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