• 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 brandonhotdo · Jun 15, 2014 at 05:36 PM · parent

No Parent?

I have a Object called "Planet(clone)" (clone because its get instantiated) and it has a child called GravRad!

 var lol;
 function OnTriggerEnter(gr : Collider){
 if(gr.transform.gameObject.name == "GravRad"){
 gr.transform.parent.gameObject.name == lol;
 Debug.Log(lol);
 }  

However in the console it says null but it has a parent in the hierarchy! oh and i have set trigger enter on and i tested without a parent and it works (so the only thing that is not working is the gr.transform.parent.gameObject.name == lol;

Comment
Add comment · Show 6
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 shigidaMark · Jun 15, 2014 at 05:40 PM 1
Share

It looks like lol is the null value - you don't have anything assigned to it (edit, though I suppose you could be doing this in-editor). You are also using a comparison operator on line 4, ins$$anonymous$$d of assigning the name to lol with only one equals sign (gr.transform.parent.gameObject.name = lol).

avatar image brandonhotdo · Jun 15, 2014 at 06:25 PM 0
Share

Yeah i got rid of the extre = but it still says null :(

avatar image Tanshaydar · Jun 15, 2014 at 06:30 PM 0
Share

Do you initialize lol? Does it have a value? Or are you trying to assign a null value to object's name?

avatar image christoph_r · Jun 15, 2014 at 07:24 PM 1
Share

Am I getting wrong what Brandon is trying to do or should lol actually be on the left hand side?

avatar image tanoshimi · Jun 15, 2014 at 07:27 PM 1
Share

Unfortunately, with such descriptive variable names as "lol" and "gr", it's a bit hard to tell what the OP's intention is! However, I tend to agree- I can't see why you'd want to set the name of the parent.

Show more comments

1 Reply

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

Answer by Kiwasi · Jun 15, 2014 at 07:37 PM

Try this. Based on the comments.

I'm assuming that you are trying to get the name of the parent.

 var parentName;
 
 function OnTriggerEnter(gr : Collider){
     if(gr.transform.gameObject.name == "GravRad"){
         parentName = gr.transform.parent.name;
         Debug.Log(parentName);
     } 
 }


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 brandonhotdo · Jun 15, 2014 at 08:43 PM 0
Share

Your a lad! It works XD

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Saving components to the parent object (Unity 4) 0 Answers

Unity 4 with new function for setting parent of GameObject? 1 Answer

Raycast always affects the same object 1 Answer

access grandfather of an object 3 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