Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 iamthecoolguy11 · Oct 25, 2013 at 04:49 AM · raycastobjectchild

set a objects child to have no parrent?

I'm making a script where you can pick objects up and put them down. This is the part that puts it down.

here are parts of the script

 var scriptHolder : GameObject;
     //if a raycast hits a rigidbody
      if(hit.rigidbody && Input.GetMouseButtonUp(1)){
 
  //trying to get the child of scriptHolder and change its child to have no parrent
               gameObject.GetComponents(scriptHolder).transform.parrent = null;
                
            }

thanks in advance :)

Comment
Add comment · Show 10
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 iamthecoolguy11 · Oct 25, 2013 at 05:09 AM 0
Share

you gave me the answer but how would i set the child of "var scriptHolder" to use gravity.

avatar image yogee · Oct 25, 2013 at 05:12 AM 1
Share

sorry i cant understand

avatar image yogee · Oct 25, 2013 at 05:15 AM 1
Share

u want to set the gravity of 'scriptHolder ' ?

avatar image fafase · Oct 25, 2013 at 05:18 AM 1
Share

parrent is parent, but still I don't get your goal.

avatar image yogee · Oct 25, 2013 at 05:23 AM 1
Share

any way, use gameObject.Find("child name").attachedRigidbody.useGravity = false/true;

Show more comments

1 Reply

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

Answer by s_guy · Oct 25, 2013 at 05:32 AM

It's not discernible what you're trying to do, but...

You can set any game object's transform to the root of the hierarchy by setting it to null. You can't do this to a component other than a transform without an error or unintended results. Most components other than the transform will not have a parent.

GetComponent() does not get a child. It gets a component. Components belong to a game object and generally do not have parents or children in any sense.

Game objects have components. One component of a game object is its transform. You can access this with .transform from the game object, and not from a component.

Transforms have parents and children. This is the structure you see in the Hierarchy.

Comment
Add comment · Show 2 · 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 fafase · Oct 25, 2013 at 05:35 AM 0
Share

Indeed, that is why I removed my answer still the purpose to have no parent but then to add gravity and finally to have no parent again...

avatar image s_guy · Oct 25, 2013 at 06:12 AM 0
Share

You can set any game object's transform to the root of the hierarchy by setting it to null. This is the same as having no parent in most senses (same as a newly created object in the editor). Sorry that I wasn't clear.

I missed coolguy's comment, but you can add gravity to any game object independent of it being parented or not. One easy way to do this is to give it a rigidbody and that will use default gravity. Though, it creates problems if a parent has a rigidbody and one of its children (or grandchildren) does too.

I could give a better answer if I understood the intent.

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

17 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

Related Questions

How to make weapon follow player arm when player model has been merged into one mesh? 1 Answer

Object Movement via Mouse Click? 3 Answers

Destroying object using his name and raycast 2 Answers

Getting the position of an object's specific tri 1 Answer

Android touch 3d Object event 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