Search Unity

instantiated child object doesn't rotate with parent

Discussion in 'Scripting' started by abysswolf, Aug 21, 2014.

  1. abysswolf

    abysswolf

    Joined:
    Oct 15, 2012
    Posts:
    62
    Code (CSharp):
    1.  
    2.         ( (GameObject)Instantiate (currentMainWeaponMesh, Ship.position, Quaternion.identity)).transform.parent=this.transform;
    3.  
    4.  

    currentMainWeaponMesh is a public gameobject of course... why it is not rotating with parent?... o.o
     
    Last edited: Aug 21, 2014
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    have you tried setting the rotation after it's created?
     
  3. abysswolf

    abysswolf

    Joined:
    Oct 15, 2012
    Posts:
    62
    howcome?
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Is it actually parented in the hierarchy? If it is, they'll rotate together.
     
  5. abysswolf

    abysswolf

    Joined:
    Oct 15, 2012
    Posts:
    62
    no they aren't they are parented via script dinamically
     
  6. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    I understand. I meant if they are parented in the hierarchy after your code is executed.
     
  7. abysswolf

    abysswolf

    Joined:
    Oct 15, 2012
    Posts:
    62
    yeah, and they don't rotate o.o
     
  8. Lars-Kristian

    Lars-Kristian

    Joined:
    Jun 26, 2013
    Posts:
    64
    Try doing it with 2 lines of code.
    You are trying to parant it to itself with the code in the first post. ;)
     
  9. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    No he's not - he's parenting the instantiated object to the object executing the instantiation code.


    If you rotate the parent via the Inspector do they rotate as you intend? If so then something in your code is wrong.
     
  10. Lars-Kristian

    Lars-Kristian

    Joined:
    Jun 26, 2013
    Posts:
    64
    Sorry, my bad.
    Is the script executed from the object you want to be the parent then?
     
  11. hariavm

    hariavm

    Joined:
    Aug 18, 2014
    Posts:
    73
    set rotation after that

    make a script to rotate lik its parent
     
  12. abysswolf

    abysswolf

    Joined:
    Oct 15, 2012
    Posts:
    62
    i solved this by changing the hierarchy of the objects, now i have annother question, but it is off thread i will make annother thread for that
     
  13. hariavm

    hariavm

    Joined:
    Aug 18, 2014
    Posts:
    73
    i never get what u telling? Can u tell the questions n the clear manner?