# FMODAudioComponent GetOwner() should change to GetAttachmentRootActor() or GetAttachmentRoot()

**URL:** https://qa.fmod.com/t/fmodaudiocomponent-getowner-should-change-to-getattachmentrootactor-or-getattachmentroot/15366
**Category:** Unreal Engine
**Created:** [January 8, 2020, 4:09am UTC](https://qa.fmod.com/t/fmodaudiocomponent-getowner-should-change-to-getattachmentrootactor-or-getattachmentroot/15366 "2020-01-08T04:09:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![D3LN](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@D3LN](https://qa.fmod.com/u/D3LN)
#### Post date: [January 8, 2020, 4:09am UTC](https://qa.fmod.com/t/fmodaudiocomponent-getowner-should-change-to-getattachmentrootactor-or-getattachmentroot/15366/1 "2020-01-08T04:09:17Z")

</div>

Sometimes the listener will be set on the CameraComponent of ViewTarget Actor but not the Actor itself, so when the CameraComponent has some offset position with the ViewTarget, the sound will be strange!

Change GetOwner() to GetAttachmentRootActor() or GetAttachmentRoot() will be better, and should choose one of them according to the situation.

Also need to judge whether the API return nullptr in function “OnUpdateTransform” or it will crash!

---

<div class="post-metadata">

### Author: ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)
#### Post date: [January 14, 2020, 10:22pm UTC](https://qa.fmod.com/t/fmodaudiocomponent-getowner-should-change-to-getattachmentrootactor-or-getattachmentroot/15366/2 "2020-01-14T22:22:47Z")

</div>

I don’t think I am understanding this correctly, can you please elaborate.

> [@D3LN](#):
>
> Sometimes the listener will be set on the CameraComponent of ViewTarget Actor but not the Actor itself, so when the CameraComponent has some offset position with the ViewTarget, the sound will be strange!

The FMODAudioComponent uses [PlayerController-\>GetAudioListenerPosition](https://docs.unrealengine.com/en-US/API/Runtime/Engine/GameFramework/APlayerController/GetAudioListenerPosition/index.html) to get the position of the listener.

> [@D3LN](#):
>
> Change GetOwner() to GetAttachmentRootActor() or GetAttachmentRoot() will be better, and should choose one of them according to the situation.

What situations are you referring to?

> [@D3LN](#):
>
> Also need to judge whether the API return nullptr in function “OnUpdateTransform” or it will crash!

Are you referring to `GetOwner()` in the `OnUpdateTransform`?

---

<div class="post-metadata">

### Author: ![D3LN](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@D3LN](https://qa.fmod.com/u/D3LN)
#### Post date: [January 15, 2020, 2:39am UTC](https://qa.fmod.com/t/fmodaudiocomponent-getowner-should-change-to-getattachmentrootactor-or-getattachmentroot/15366/3 "2020-01-15T02:39:16Z")

</div>

I found in file “FMODAudioComponent.cpp”, you are using “GetOwner()” API in some function like “void UFMODAudioComponent::OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETeleportType Teleport)”.  
It may be unsafe if there is three or more layer tree struct and the “FMODAudioComponent” to be the bottom layer. Such as “SceneComponent”(first layer) -\> “CameraComponent”(second layer) -\> “FMODAudioComponent”(third layer).  
This struct may exist because UE4 Actor tree struct is actually component tree struct, with the first layer component as “RootComponent” of “Actor” and the “Actor” owns the second layer as “Owner”. But from the third layer, component can’t get the owner “Actor” from “GetOwner()” API, it will return null. The only way for all component in any layer to get the “Actor” is using “GetAttachmentRootActor()” API.  
And also, sometimes you should consider get the parent component using API “GetAttachmentRoot()” to calculate the position of “FMODAudioComponent”, cause every component in the tree struct has it’s own position transform while the owner “Actor” doesn’t has any position transform but just using transform of its “RootComponent”.

So I suggest you to use “GetAttachmentRootActor()” and “GetAttachmentRoot()” API to replace “GetOwner()” API in “FMODAudioComponent.cpp”.

---

<div class="post-metadata">

### Author: ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)
#### Post date: [January 20, 2020, 4:36am UTC](https://qa.fmod.com/t/fmodaudiocomponent-getowner-should-change-to-getattachmentrootactor-or-getattachmentroot/15366/4 "2020-01-20T04:36:21Z")

</div>

Thanks very much for the information, I will raise this as a task to investigate further.
