Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Clone object as it on scene ?

Discussion in 'Scripting' started by Quast, Jun 7, 2019.

  1. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    I'm facing this strange issue when trying to duplicate object on game scene I got it on different sizes.
    Because there are many other parts I can't use transform.localScale.
    I need to clone those object without changing the object scale.
    Code (CSharp):
    1.                 Transform bm = Instantiate(maz_clone) as Transform;
    2.                 //bm.transform.localScale = new Vector3(3,5,12); // I can't use this
    3.                 bm.transform.position = BulletMagazin.transform.position;
    How to solve this ?
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Either specify same parent object or copy lossyScale value from original object.
     
  3. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    I have to do it manually.
    Thank you.
     
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Are you sure you're getting the object in the scene and not the prefab it came from?
    You're not showing enough code for us to tell by ourselves.
     
  5. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    Yes. this different in the size I think because it comes from child object. Anyway, to solve this I have to make one empty object and insert my object inside it"Later will paste the correct values". Use "localScale" for empty object. Now, when I get my clone object change it values size to fit my original object. Copy these values and use it. It did work for my case. Thank you guys.