Jump to content
  • Advertisement
Sign in to follow this  
rogerdv

Problem instantiating objects

This topic is 1165 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!