instantiated object not moving with parent transform.

hi all!

thanks for taking a look :slight_smile:

i am attempting to instantiate a vfx prefab with the transform of an existing game object, and then parent that instantiated object to another object.
the desired effect is to have vfx spawn off a character’s hand, and then travel with the character animation while retaining the position and orientation of its parent object.

in the code below, if the (Transform gauntletL_vfx) is left empty, the object will be instantiated but without retaining its parent’s position.

as you can tell, i am new to scripting. any feedback is welcome.

thanks!

using UnityEngine;
using System.Collections;

public class InstantiateGauntletVFX : MonoBehaviour 
{
	public GameObject gauntletVFX_01;
	public Transform gauntletL_vfx;

	public void OnVFXTrigger (Transform gauntletL_vfx)
	{
		Instantiate(gauntletVFX_01, gauntletL_vfx.position, gauntletL_vfx.rotation);
		gauntletVFX_01.transform.SetParent(gauntletL_vfx, false);
	}
}

the returned value from function Instantiate is the new created object,so you could use it, not the original prefab gauntletVFX_01:

     public void OnVFXTrigger (Transform gauntletL_vfx)
     {
         GameObject tmp = Instantiate(gauntletVFX_01, gauntletL_vfx.position, gauntletL_vfx.rotation) as GameObject;
         tmp.transform.SetParent(gauntletL_vfx, false);
     }