Search Unity

Bug There is something wrong with Instantiate defaults

Discussion in 'Editor & General Support' started by mfatihbarut, May 27, 2021.

  1. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,059
    Instantiate act weird by default.
    It changes scale unintendedly.
     
    Last edited: May 27, 2021
  2. Could you please demonstrate when it is wrong? I mean with hard facts and examples, not just some vague, meaningless phrases. You know, providing proof is a big part of Mathematics.
     
  3. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,059
    the code below is supposed to spawn a spear object using the spear object in the scene. But instantiated spears have inconsistent scales.
    GameObject Spear = Instantiate(Spell, Spell.transform.position, Spell.transform.rotation, gameObject.transform);
     
  4. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,059
  5. MagicianArtemka

    MagicianArtemka

    Joined:
    Jan 15, 2019
    Posts:
    46
    This looks strange. If you are sure, that your another components and/or animation stuff can't cause that - try to Play with instantiateInWorldSpace parameter https://docs.unity3d.com/ScriptReference/Object.Instantiate.html

    I know, that documentation says this is only for position and rotation, but who knows, Unity documentation never was actual and updated in time.
     
    Last edited: May 27, 2021
  6. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,059
    I had tried it first it wasn't also the solution.
     
  7. Just for the debugging's sake:
    - create a cube, scale it to x: .2f, y: .2f, z: 1f
    - hide your spear
    - add this cube as spawning
    - observe if the problem still persists
    - if it does, try to add an empty game object and make the cube child of it
    - observe again

    if the problem doesn't appear with your scaled cube, then something on your prefab is acting up, you need to check what's causing the problem.
     
  8. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,059
    inconsistency was related to code triggered by an animation event.
    But still, scale is a big problem for instantiate.
     
  9. ?