- Home /
Instantiate a Prefab as child
Hello,
I try to Instantiate a Weapon as an Child of a Empty Gameobject which is in Position with the Right Hand of my Model ,it works well but the Position of the Weapons are not correct ...
GameObject w = Instantiate(ca.WeaponMesh[_weaponIndex],_pc.WeaponMount.transform.position,_pc.WeaponMount.transform.rotation)as GameObject;
w.transform.parent = _pc.WeaponMount.transform;
What i doinig wrong ???
This looks solid. Only thing i can think of is bad pivot points.
If the position is not correct, why not change it?
Just set the localPosition to Vector3.zero after your parent
I suspect the problem is that you're setting a non-zero position. Since you're parenting the object, its local position should be zero because it will be inherit the position from the parent.
He shouldnt really need to set it to zero though, when he sets position first, and then parents, it should become Vector3.zero on its on (locally). Are your scales fucked or something?
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Parenting GameObjects 1 Answer
iOS Instantiate transform as child -- positioning bug 2 Answers
Howto set main.camera as a parent when main.camera itself is a child of a prefab 1 Answer
setting the parent of a transform which resdes in a prefab is dusabled to prevent data corruption 1 Answer