This is driving me absolutely batty! Here is what is happening and I just don't understand
In the editor my parent object has a scale of 100,100,100
the prefab has a transform as follows:
Position: 0, -1.939, 0 Rotation: 0, 0, 0 Scale: 0.3946165, 0.3946165, 0.3946165
If I drag this to the parent it looks perfect, exactly as I want.
I export the prefab as an AssetBundle and import at runtime like this:
currentPerson = Instantiate(bundle.mainAsset,new Vector3(0, -1.939f, 0), Quaternion.identity) as GameObject;
currentPerson.transform.localScale = new Vector3(300, 300, 300);
currentPerson.transform.parent = GameObject.Find("PeopleImageTarget").transform;
Debug.Log(currentPerson.transform.position.x + ", " + currentPerson.transform.position.y + ", " + currentPerson.transform.position.z);
Debug.Log(currentPerson.transform.rotation.x + ", " + currentPerson.transform.rotation.y + ", " + currentPerson.transform.rotation.z);
Debug.Log (currentPerson.transform.localScale.x + ", " + currentPerson.transform.localScale.y + ", " + currentPerson.transform.localScale.z);
Now the child object appears but it is still tiny and where I have the scale set to 300 to try to increase its size it reports 3 in the debug log
This is running as an exported to IOS app maying use of the augmented reality tool from Vuforia hence the parent scale being 100
If I include the child in the app and simply set active on or off the child appears perfect it is only going tint when instantiating which is a feature I need to import models at runtime....
transform.SetParent
and take note of theworldPositionStays
parameter: docs.unity3d.com/ScriptReference/Transform.SetParent.html – Chris McFarland