Problem instantiating objects

Started by
1 comment, last by rogerdv 9 years ago

Im trying to use Instantiate() to equip an intem in the character model, the object is created in the expected point, but stays there instead of moving with the character mesh. This is my code:


GameObject weapon = Resources.Load("items/ancient-grtsword") as GameObject;
Instantiate(weapon,t.transform.position, Quaternion.identity); 
weapon.transform.SetParent(t.transform);
weapon.transform.position = Vector3.zero;

t is a GameObject, assigned from the editor. I have tried both using the bone (the mesh has an specific bone to attach the item), and creating an empty GameObject in the bone and using it. How can I solve this?

Advertisement

Try setting weapon.transform.localPosition to zero after the parent assignment. See if that helps?

Also, have you looked in the scene hierarchy during runtime to make sure the parenting is attaching to the object you expect? For example, is t still a child element of the character model?

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

Thanks! using localPosition/Rotation solved my problems. Now Im looking some way to store a database with alol the required rotations/offsets, I thought I could handle that with the prefab.

This topic is closed to new replies.

Advertisement