Instantiate Prefab on spawned Gameobject

Hi!

I’m trying to add some flair to my combat system by adding a particle effect whenever a weapon hits an enemy. The thing I’m running into is that particle effect is not spawning at the current location of the weapon. It keeps spawning at the same location outside of my level.

I’m using this script to test it out:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponEffects : MonoBehaviour
{
public GameObject effect; //This is the effect that plays on weapon.

// Update is called once per frame
private void Start()
{
    Debug.Log("Trigger Effect");
    Instantiate(effect, transform.position, Quaternion.identity); //This is the effect when weapon hits an enemy.
}

}

Could anyone help me out?

Kind Regards

Where exactly is that Start() function located? Since the instantiation is done in a Start() method, is that script being instantiated as part of a new gameobject after a positive trigger check?

My thoughts right now are that you have the “WeaponEffects” script inside a gameobject, which isn’t moved at all during runtime. That would explain why the particle effect isn’t changing position, since in the Instantiate method you are setting the effect’s position as the current transform’s position.