Instantiated prefab scale is wrong.

Hello, and I hope my first question here hasn’t been answered in a million places, I have been looking all day.

I have a project that instantiates a prefab (sol1) through a script using this code.

var sol1 : Transform;
var a1s = Instantiate(sol1, Vector3(0, 0, 0), Quaternion.identity);

This code was directly lifted from another project and works famously, but when used in this project the prefab is instantiated with the wrong scale, usually 0.999999 something on all axis. This does not happen in any of my other projects, where prefab scale is simply carried over into the scene. I don’t understand why this happens here. Also, trying to access the scale to change it after it is instantiated has no effect. I have tried instantiating it to the position and rotation of an empty, but it is the same. It seems everything does what it is supposed to, except it refuses to keep the prefab scale and let me access the scale after the object is spawned. I have also tried this with two versions of the prefab, one off the project list and one out of the scene itself, with no difference. Bringing in and using a prefab that worked in a separate project with this code resulted in two out of three axis over-scaling incorrectly with the third scaled down to 1.

I am unbelievably lost in what looks to me like random behavior in Unity and I have no idea what to try next beyond just scrapping it and starting over. Please help!

-Brother B

I found the problem, and I feel like such a moron. The problem is with Blender 2.61, not Unity. I tried all sorts of ways to modify and re-export the objects with no luck. I opened a new Blend file, made a new object from scratch, and exported it into the project. It too had the scaling problem. Finally, I gave up, and as a last ditch attempt I re-opened my original model in Blender 2.59 instead of 2.61 and exported it one last time, this stopped the forced rescaling.

I’m really happy to know I’m not crazy and I would like to say that I LOVE Unity and was perfectly willing to do what it takes to work around this if necessary. Thanks, everyone, for helping out.

-Brother B.

I ran into the same situation when I instantiated a prefab with several images.

For some reason, the background did not scale correctly, but everything else did.

None of the advice above worked, however, this worked for me.

Save the prefab as inactive.
After instantiating the game object, instantiate it.

Thus:

//Make sure the prefab is not active
public GameObject currentBackground = null;
public GameObject prefab;
public GameObject template; // placeholder for object

    currentBackground = (GameObject)Instantiate(prefab);
    if (currentBackground != null)
    {
        currentBackground.transform.SetParent(template..transform.parent, false);
        currentBackground.transform.position = template.transform.position;
        currentBackground.SetActive(true);
    }

One important thing to know is that any change to the transform of an instance prefab will not be reflected on the original prefab when clicking on “Apply”. This can be easily understood: while you want all your instantiated prefabs to share every components and parameters, you may want to have them at different place/size/rotation without breaking prefab connection.

  1. Verify that your prefab (not an instance of this prefab in your scene) scale is indeed (10, 10, 10).
  2. Try to instantiate your prefab using the method with one argument only (although I’m pretty confident that the other one will still work).

I did some test. It worked fine for me.