- Home /
Tiny instantiated GameObject
I have a prefab that when I drop on my scene appears at exactly the correct scale, rotation and position.
I create an empty GameObject and copy the prefabs transform to it and call this empty GameObject SpawnLocation
I then delete the prefab from the scene.
In my script I have this code:
GameObject obj = Instantiate(MyObject, spawnLocation.position, spawnLocation.rotation) as GameObject;
obj.transform.parent = parentTransform;
MyObject is set to being the prefab I set in the editor and spawnLocation is set to the transform of the empty GameObject in the scene named SpawnLocation
parentTransform is set to the plane in the scene to which the instantiated object should be child to.
All good so far.....apart from the instantiated object appears in the correct place.....but is tiny?
It does not appear at the same scale as the prefab?
I drop again the prefab into the scene in the editor and it appears correct?
So how come I have an instantiated object of this prefab and using its same transform it appears so small?
Thanks
Weird, but just assign it's
transform.scale=Vector3.one;
before parenting it...
Hi,
Thanks..
there is no scale property so tried
obj.transform.localScale=Vector3.one;
with no success :-(
Remember to post comments as actual comments by using the "Add new Comment" button (I converted this one for you).
What are the parent transform values? if it has some not (1, 1, 1) scale - children inherit this.
hav_ngs_ru .... you hero :-)
Thanks, how do I accept your answer as the solution?
Thanks again ;-)
If the parent transform is reducing the scale, the child object will appear small. (Though, I would have though assigning that transform as the parent would invert that in the localScale). $$anonymous$$aybe check the parent transforms for something like that? What happens if you don't assign a parent? (like when you drag it into the scene)
Answer by elpuerco63 · Feb 05, 2015 at 10:35 AM
and the resolution is:
currentPerson.transform.SetParent(obj.transform, false);
sorted :-)
Face Palm All my stupid workarounds, and that function was there the whole time? Gosh, I need lessons how how to properly use DOCU$$anonymous$$ENTATION, lol.
(btw: if this WOR$$anonymous$$ED for you that would indicate you WERE setting the transform's local values BEFORE assigning the parent, not that it matters anymore.)
Answer by SnStarr · Jan 29, 2015 at 01:27 PM
When you are instantiating the prefab onto the plane it is inheriting the properties of it's parent object which probably has a scale of less than 1 which is making the prefab also have a scale of less than one. Try resetting parents scale to one. Or setting the instantiated prefabs scale to 1 before parenting in script.
I thought I had this fixed, alas not and Im confused by it.
If I drag my prefab onto the parent object in the scene it appears in correct position and size.
The parent scale is 100,100,100 and when dropped the prefab scale is 1.942413, 1.942414, 1.942414
But if I instantiate the object and parent it alas it still appear tiny, even if I set the objects scale before setting its parent?
Your answer
Follow this Question
Related Questions
How can I spawn gameObjects within a circle radius? 1 Answer
How can I add the OnTriggerEnter function to all game objects that I instantiate? 1 Answer
Creating a GameObject variable without instantiating it? 1 Answer
LayoutKind.Explicit FieldOffset structs getting wrecked at Instantiate() 1 Answer
[Solved]Instantiating prefab from a script and destroy it from another one 2 Answers