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 Treven · May 10, 2016 at 05:59 AM · scripting problemparentchildlayersparent-child

Child cant apply variables from parent

I trying to pass my parent variables to my child they are passing but I'm get a NullReferenceException: Object reference not set to an instance of an object. I checked all the answers on this and could not find an answer but I might of found a clue that my parent is not getting the child of my child but i'll post the code down there i still get the same result If you could help (or direct me some one who knows how to fix this.). Help is much appreciated. (I cut out code parts that are not likely part of the problem.)

the Layered objects are: Player (Parent Script here) groundcheck imported model Material of model HitBox(The Child Script here)

And the parent communication script

    HitBoxCollider hitBox;
 
 void start()
 {
     hitBox = transform.GetChild(1).GetComponentInChildren<HitBoxCollider>(); // also tried this this hitBox = transform.GetComponentInChildren<HitBoxCollider>();
  }   
     void Update
     {
        HitBoxData();
     }
     
     void HitBoxData()
         { /*these are giveing me a NullReferenceException: Object reference not set to an instance of an object. */
                 hitBox.knockBackX = knockBackX1;
                 hitBox.knockBackY = knockBackY1;
                 hitBox.knockBackLength = knockBackLength;
                 hitBox.damageToGive = damageToGive;
          }
 

And the child communication script

 PlayerControls pc;
 
     void Start () {
         pc = transform.parent.GetComponentInParent<PlayerControls>();
     }



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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by pankajb · May 10, 2016 at 02:27 PM

I noticed from your previous question that you are disabling hitBox in start method.

  // Use this for initialization
  void Start () {
      pc = transform.parent.GetComponentInParent<PlayerControls>();
      hitBox.SetActive(false);
  }

did you change setActive to true somewhere ?

Comment
Add comment · Show 3 · 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 Treven · May 10, 2016 at 03:30 PM 0
Share

yes It goes to true within animations but have tried leaving it on and got the same result

avatar image Treven · May 11, 2016 at 08:54 AM 0
Share

Okay its like 75 percent fixed the problem was when i renamed my gameobject that had the script from hitter to hitbox and found another fix where the game object has to be on all the time or the script that it is comunicating with will run into an error. now i got new problem how can i have the playercontrols ignore the script when current attack script isn't in use. the closest work around i found was making the radius as close to zero and have it controlled through animation.

avatar image Treven · May 16, 2016 at 01:43 PM 0
Share

okay i fixed my problem and had to redo alot of things but is now working

avatar image
0

Answer by rober-psious · May 10, 2016 at 02:18 PM

Your function is not being called because start is not equal than Start ;)

Check line 3 of your code.

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 Treven · May 10, 2016 at 03:32 PM 0
Share

Sorry but i typed the code into the code section i forgot to capitalize the start sorry but its already capitalized in the actual code.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Adressing a Child Object after it´s unparented 0 Answers

Make child's transform independent of parent 1 Answer

Change an object's grandparent 2 Answers

Script that mimics a child object behavior. 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