How to Use set3dattributes for Event Instance in C++?

Hi! I’m trying to update the position of an FMOD event instance so the sound follows along when my actor is moving. But when I use “set3DAttributes” the event doesn’t sound anymore at all. I’m not getting any error from either get or set. I’ve tried printing out my actor location and compare it with the updated position from get3DAttribures and they are identical. What am I missing?

// ==== Header ====

FFMODEventInstance MovingSfxInstance;

// ==== Source ====

FMOD_3D_ATTRIBUTES Fmod3dAttributes;
FMOD_RESULT result = MovingSfxInstance.Instance->get3DAttributes(&Fmod3dAttributes);

if (result != FMOD_OK) 
{
	Helper::Log("FMOD ERROR:", result);
}

Fmod3dAttributes.position = FmodManager::ConvertToFmod(NewLocation);

FMOD_RESULT setResult = MovingSfxInstance.Instance->set3DAttributes(&Fmod3dAttributes);

if (setResult != FMOD_OK)
{
	Helper::Log("setResult:", setResult);
}

// ==== Helper function ====

FMOD_VECTOR FmodManager::ConvertToFmod(FVector Vector)
{
	FMOD_VECTOR FmodVector;

	FmodVector.x = Vector.X;
	FmodVector.y = Vector.Y;
	FmodVector.z = Vector.Z;

	return FmodVector;
}

Anyone? :slightly_smiling_face:

Hi Tobias

It looks like you maybe copying a UE4 location into FMOD without taking care of the transformation from UE4 coordinate system to the FMOD coordinate system (the code you shared doesn’t show NewLocation being transformed)?

UE4 and FMOD use different coordinate systems so when passing 3D positions or orientations from UE4 to FMOD they need to be transformed to the correct coordinate system. There is a function in our integration, FMODUtils::ConvertWorldVector which accepts a UE4 FVector representing a UE4 world space position and returns a correctly transformed FMOD_VECTOR to use with our API. I suggest you try using that function, or check out the implementation as a guide if you prefer to roll your own.

Cheers
Derek

1 Like

Hi Derek,

That was the issue, thanks a lot!

1 Like