tranek / GASDocumentation

My understanding of Unreal Engine 5's GameplayAbilitySystem plugin with a simple multiplayer sample project.
MIT License
4.26k stars 789 forks source link

OnAvatarSet called with player state #128

Closed reisandbeans closed 7 months ago

reisandbeans commented 7 months ago

I was trying to follow the suggestion of initializing passive abilities in the OnAvatarSet function, but I found a problem with it. I'm not sure if I'm doing anything wrong, but that function is called twice in my player: once with PlayerState as both the OwnerActor and the AvatarActor, and then again a few millisecond later with PlayerState as the OwnerActor, and the player character as the AvatarActor (which is what I expected in the first place).

I'm not sure why it happens or why it's called twice - maybe it's something I'm doing wrong - but it causes me a problem because one of my passive abilities is a line trace for identifying interactable objects, and I use the character mesh as the starting point of the trace. Since on the first call, PlayerState is set as the Avatar, there's no mesh in there. Does anyone have a suggestion in that case? Should I add some sort of check to OnAvatarSet to verify if PlayerState is still the Avatar on ActorInfo and skip it (this sounds a bit hacky, to be honest) ?

reisandbeans commented 7 months ago

Actually, I after some investigation, I noticed that OnAvatarSet is being called from GiveAbility, which I was being called from InitActorInfo. It seems that InitActorInfo is called once by the Ability System component itself, passing the owner as both the owner and avatar - which I still don't quite understand why. But I suppose I can re-organize my code and make sure I call GiveAbility only after the avatar is properly set