- Home /
Issue with changing localScale of gameobject after instantiate
Hi,
I'm at a loss to figure out why modifying the local scale of an instantiated GameObject does not work immediately after instantiating. Best way to explain (PrefabManager contains lists to my prefabs, it's been thoroughly tested and has worked for months!):
This does not work, the scale changes are lost::
myPrefabModel = (GameObject)GameObject.Instantiate(PrefabManager.theEquipmentModels["modelName"]);
myPrefabModel.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
This works:: (the method is called as a Coroutine)
myPrefabModel = (GameObject)GameObject.Instantiate(PrefabManager.theEquipmentModels["modelName"]);
yield return new WaitForSeconds(1.5f);
myPrefabModel.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
It seems I have to wait a very long time (1.5 secs minimum) in order to be allowed to alter the scale. I would much rather be able to do it immediately, it's not very pleasing aestethically!
Many thanks for the help to come,
Ben
Can be that any script attached to you prefab changes the scale? So when you instantiate it with no delay one of your scripts change it back right after you, and when you delay it the script change it before you?
I see what you mean, but no. This prefab has no scripts attached to it. I was thinking of this being the cause but that's simply not possible, I have no other lines of code that alter the scale.
As it is I only need to alter scale because my models are not all on an equivalent scale, and i've got no time to redo all the animations ( Blender issue with rescaling, animations do not rescale and end up gibberish ).
Well I can change the scale of my models directly after instantiation and have no problems - so this is not a restriction in Unity. Is something setting the parent of that transform perhaps - thereby making the scale have a different effect?
WhyDoIDoIt -- Hvilela, thanks for your prompt responses.
I went back and tested the only thing i hadn't changed -- which is the model. I came across another post of someone that had troubles with his blender model imports in regards to animations.
And hazaa. I removed the animations in the import wizard for this model and it has solved my troubles. Unity was most likely spinning a few cycles on some bad animation data from the blender file.
Thanks!
Answer by benoit20 · Sep 27, 2012 at 02:55 PM
For reference, the problem was due to the blender model, specifically animations in the model. Removing them in the import wizard solved the problem.