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 Loozers_Beware · Jun 13, 2017 at 01:16 AM · positioningparent transformunparenting

transform.parent = null; not working

so, i'm trying to make an object duplicate itself then have the original unparent from the hips and have the duplicate stay in place. It duplicates perfectly fine and parents the duplicate to the hips perfectly fine, however the original still moves with the hips despite "transform.parent = null" being in the code. Can anyone tell me what i am doing wrong?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Magazine : MonoBehaviour {
 
     public int ammo = 6;
     private bool duped = false;
     public GameObject mag;
     public Transform Hips;
     // Use this for initialization
     void Start () {
         
     }
     public int GetAmmo()
     {
         return ammo;
     }
     public bool GetDuped()
     {
         return duped;
     }
     public virtual void WasDuped(int ammos)
     {
         duped = true;
         GameObject mag = Instantiate(Resources.Load("MagSpawner"), gameObject.transform.position, gameObject.transform.rotation) as GameObject;
         ammo = ammos;
         mag.transform.parent = Hips;   //this works fine
         transform.parent = null;      // <------the line that does not work 
 
     }
     public virtual void SetAmmo(int ammos, GameObject self)
     {
         ammo = ammos;
         if (ammo <= 0) {
             Destroy (self, 2f);
         }
     }
     // Update is called once per frame
     void Update () {
         
     }
 }
 
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 hexagonius · Jun 13, 2017 at 10:33 AM 0
Share

Does it show as a child in the hierarchy?

avatar image Loozers_Beware hexagonius · Jun 13, 2017 at 02:48 PM 0
Share

yes it does

avatar image Hellium · Jun 13, 2017 at 02:54 PM 1
Share

Have you tried to call the transform.SetParent(null) ins$$anonymous$$d of the property ?

avatar image Loozers_Beware Hellium · Jun 13, 2017 at 02:57 PM 0
Share

just tried it and it didn't work

avatar image Hellium · Jun 13, 2017 at 03:44 PM 0
Share

Any error in the console ? (make sure Errors are enabled) What does Debug.Log( transform.parent ) ; outputs after you try to detach the child ?

avatar image Loozers_Beware Hellium · Jun 13, 2017 at 04:27 PM 0
Share

Null UnityEngine.Debug:Log(Object) $$anonymous$$agazine:WasDuped(Int32) (at Assets/Guns/$$anonymous$$agazine.cs:33) VRT$$anonymous$$.GrabAttach$$anonymous$$echanics.$$anonymous$$agGrab:CreateJoint(GameObject) (at Assets/Guns/$$anonymous$$agGrab.cs:38) VRT$$anonymous$$.GrabAttach$$anonymous$$echanics.VRT$$anonymous$$_BaseJointGrabAttach:SnapObjectToGrabToController(GameObject) (at Assets/VRT$$anonymous$$/Scripts/Interactions/GrabAttach$$anonymous$$echanics/VRT$$anonymous$$_BaseJointGrabAttach.cs:128) VRT$$anonymous$$.GrabAttach$$anonymous$$echanics.VRT$$anonymous$$_BaseJointGrabAttach:StartGrab(GameObject, GameObject, Rigidbody) (at Assets/VRT$$anonymous$$/Scripts/Interactions/GrabAttach$$anonymous$$echanics/VRT$$anonymous$$_BaseJointGrabAttach.cs:43) VRT$$anonymous$$.VRT$$anonymous$$_InteractGrab:IsValidGrabAttempt(GameObject) (at Assets/VRT$$anonymous$$/Scripts/Interactions/VRT$$anonymous$$_InteractGrab.cs:381) VRT$$anonymous$$.VRT$$anonymous$$_InteractGrab:PerformGrabAttempt(GameObject) (at Assets/VRT$$anonymous$$/Scripts/Interactions/VRT$$anonymous$$_InteractGrab.cs:366) VRT$$anonymous$$.VRT$$anonymous$$_InteractGrab:AttemptGrabObject() (at Assets/VRT$$anonymous$$/Scripts/Interactions/VRT$$anonymous$$_InteractGrab.cs:355) VRT$$anonymous$$.VRT$$anonymous$$_InteractGrab:DoGrabObject(Object, ControllerInteractionEventArgs) (at Assets/VRT$$anonymous$$/Scripts/Interactions/VRT$$anonymous$$_InteractGrab.cs:402) VRT$$anonymous$$.VRT$$anonymous$$_ControllerEvents:OnAliasGrabOn(ControllerInteractionEventArgs) (at Assets/VRT$$anonymous$$/Scripts/Interactions/VRT$$anonymous$$_ControllerEvents.cs:741) VRT$$anonymous$$.VRT$$anonymous$$_ControllerEvents:EmitAlias(ButtonAlias, Boolean, Single, Boolean&) (at Assets/VRT$$anonymous$$/Scripts/Interactions/VRT$$anonymous$$_ControllerEvents.cs:1695) VRT$$anonymous$$.VRT$$anonymous$$_ControllerEvents:Update() (at Assets/VRT$$anonymous$$/Scripts/Interactions/VRT$$anonymous$$_ControllerEvents.cs:1100)

avatar image Loozers_Beware Hellium · Jun 13, 2017 at 04:29 PM 0
Share

but no error raised in console

0 Replies

· Add your reply
  • Sort: 

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

67 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

Related Questions

How do I move both the parent and child to a known position where I want the child to be? 1 Answer

Placing items on terrain in the editor 3 Answers

Object resets position on first movement. 1 Answer

moving the main game window 0 Answers

Multidimensional Array of Vector2 2 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