Unable to properly interpolate an event in 3D space

Hi. I’ve been stuck for hours trying to attach my fmod Event to a moving object’s position. The idea is to hear a projectile passing by when the player is close to the trajectory. Here’s my code :

    public void PiratePatternAudioObjectCreate()
    {
      m_shootFinalTarget = new GameObject("shootFinalTargetLocation");
      m_lerpingObject = new GameObject("lerpingObject");
    }

    public void PiratePatternAudioObjectDestroy()
    {
      Destroy(m_shootFinalTarget);
      Destroy(m_lerpingObject);
    }

    public void PiratePatternShootObstacle(Vector3 shootFinalTarget)
    {
      if(m_shootObstacleTimer <= 1)
      {
        PiratePatternAudioObjectDestroy();
        PiratePatternAudioObjectCreate();

        m_shootFinalTarget.transform.position = shootFinalTarget;

        currentPos = m_boatController.Physics.transform.position;
        targetPos = m_shootFinalTarget.transform.position;

        RuntimeManager.PlayOneShotAttached(m_piratePatternShoot.Guid, m_boatController.Physics.gameObject);
        RuntimeManager.PlayOneShotAttached(m_piratePatternShootObstacleHit.Guid, m_shootFinalTarget);
        // RuntimeManager.PlayOneShotAttached(m_piratePatternShootWhoosh.Guid, m_lerpingObject);
         m_piratePatternShootWhooshInstance = RuntimeManager.CreateInstance(m_piratePatternShootWhoosh);

         m_piratePatternShootWhooshInstance.start();
         m_piratePatternShootWhooshInstance.release();
      }
      m_lerpingObject.transform.position = currentPos;

      float obstacleLenght = Vector3.Distance(m_boatController.Physics.transform.position, targetPos);
      float speed = 40f;
      m_shootObstacleTimer += 1;

      if(m_shootObstacleTimer > 1)
      {
        currentPos = Vector3.MoveTowards(currentPos, targetPos, speed * Time.deltaTime);
        RuntimeManager.AttachInstanceToGameObject(m_piratePatternShootWhooshInstance, m_lerpingObject);
        if(Vector3.Distance(m_lerpingObject.transform.position, targetPos) < 0.1)
          m_lerpingObject.transform.position = targetPos;
      }

As the projectile is triggered, my function PiratePatternShootObstacle is called. It creates an object “m_lerpingObject” which is moving from the enemy to a hit point. What I want is to get my event to follow this object. In order to do so, I used the AttachInstanceToGameObject Function. While profiling, I can see that whenever the event is called, it fires really far away from the enemy, but in the same direction as my hit point, but I can’t figure out why.


So I slept on it and here is where I was wrong. I was creating my EventInstance in another condition that the one responsible for interpolating my gameObject. I don’t really know why, but trying to access the already created Instance from a different condition by using RuntimeManager.AttachInstanceToGameObject(instance, gameObject) doesn’t affect the Instance.
In order to make it work I just has to create my instance in the same place where it is connected to my 3D gameObject position, making sure to limit the instance max number to 1(with no stealing) in fmod studio’s event editor since it is called every frame :

public void PiratePatternShootObstacle(Vector3 shootFinalTarget)
    {
      if(m_shootObstacleTimer <= 1)
      {
        PiratePatternAudioObjectDestroy();
        PiratePatternAudioObjectCreate();

        m_shootFinalTarget.transform.position = shootFinalTarget;
        m_lerpingObject.transform.position = m_boatController.Physics.transform.position;
        targetPos = m_shootFinalTarget.transform.position;

        RuntimeManager.PlayOneShotAttached(m_piratePatternShoot.Guid, m_boatController.Physics.gameObject);
        RuntimeManager.PlayOneShotAttached(m_piratePatternShootObstacleHit.Guid, m_shootFinalTarget);
      }
      // float obstacleLenght = Vector3.Distance(m_boatController.Physics.transform.position, targetPos);
      float speed = 40f;
      m_shootObstacleTimer += 1;

      if(m_shootObstacleTimer > 1)
      {
        m_lerpingObject.transform.position = Vector3.MoveTowards(m_lerpingObject.transform.position, targetPos, speed * Time.deltaTime);
        m_piratePatternShootWhooshInstance = RuntimeManager.CreateInstance(m_piratePatternShootWhoosh);
        RuntimeManager.AttachInstanceToGameObject(m_piratePatternShootWhooshInstance, m_lerpingObject.transform);
        m_piratePatternShootWhooshInstance.start();
        m_piratePatternShootWhooshInstance.release();
      }