Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Attribute initialisation now gets properly initialised in server and client #68

Closed
wants to merge 1 commit into from

Conversation

vorixo
Copy link
Contributor

@vorixo vorixo commented Oct 6, 2021

I have some non replicated attributes I'd like to initialise in both, Authority and Autonomous Proxy.

For that I am adding an initializer gameplay effect in the character in PossessedBy (auth) and OnRepPlayerState (aut/sim-proxy).

Well turns out that GASDocumentation ASC lives in the PS, and when I am adding the effect in OnRep_PlayerState, my attributes dont get initialised in the autonomous proxy, but the simulated proxies... i could diagnose a bit, and it seems that even if the character is autonomous proxy in onrep_playerstate, the PS is simulated proxy... so I effectively dont have a way to init non replicated Attributes in the Autonomous Proxy through the offered original method.

TODO: Address this in the documentation since I find it pretty relevant for ASCs that live in the PS.

…server and client

- Previously it was initialised only on the server as the Applying effects requires the  owner to be autonomous or authority
@tranek
Copy link
Owner

tranek commented Dec 3, 2021

I see what your issue is, however it is specific to your game - having non-replicated attributes. I won't be including this change in GASDocumentation's code.

Reading the modifiers out of a GameplayEffect feels weird. I'd probably recommend making a TMap<FGameplayAttribute, float> on the AvatarActor's class and iterating through the pairs instead of using GEs.

@tranek tranek closed this Dec 3, 2021
@vorixo
Copy link
Contributor Author

vorixo commented Dec 3, 2021

Hey Dan, it's not really a project specific thing.

It's about fast client initialization even with replicated attributes.

If you want to consume the attribute value right after initialisation in the client (for prediction reasons) you won't be able to do it with your method, because as I pointed out above FActiveGameplayEffectHandle ActiveGEHandle = AbilitySystemComponent->ApplyGameplayEffectSpecToTarget(*NewHandle.Data.Get(), AbilitySystemComponent.Get()); will do nothing in the client.

If you don't want to benefit from client initialization. I recommend wrapping that initialisation code with a HasAuthority and remove the "can run in server and client" comment.

@tranek
Copy link
Owner

tranek commented Dec 7, 2021

If you want to consume the attribute value right after initialisation in the client (for prediction reasons) you won't be able to do it with your method, because as I pointed out above FActiveGameplayEffectHandle ActiveGEHandle = AbilitySystemComponent->ApplyGameplayEffectSpecToTarget(*NewHandle.Data.Get(), AbilitySystemComponent.Get()); will do nothing in the client.

Without a valid prediction key, this will do nothing on the client. That is correct and the call to InitializeAttributes() in AGDHeroCharacter::OnRep_PlayerState() can be removed as it's not doing anything.

It's about fast client initialization even with replicated attributes.
If you want to consume the attribute value right after initialisation in the client (for prediction reasons)

For GASDocumentation, the server initializes the attributes in AGDHeroCharacter::PossessedBy(). If the attributes aren't already initialized in the PlayerState replication, then they will be immediately after. I don't know the order here and I'm guessing it happens in the same frame. There won't be any time to predict anything before the attributes are initialized from the server.

@vorixo
Copy link
Contributor Author

vorixo commented Dec 7, 2021

Without a valid prediction key, this will do nothing on the client. That is correct and the call to InitializeAttributes() in AGDHeroCharacter::OnRep_PlayerState() can be removed as it's not doing anything.

Correct, and since this can lead to confusion I think it's better to make it more explicit, I'll try to work towards a more convenient solution given the use case presented here.

For GASDocumentation, the server initializes the attributes in AGDHeroCharacter::PossessedBy(). If the attributes aren't already initialized in the PlayerState replication, then they will be immediately after. I don't know the order here and I'm guessing it happens in the same frame. There won't be any time to predict anything before the attributes are initialized from the server.

I mean... given that abilities can only be granted in the server... But if you consume an attribute in the client at the begining of the game, on a very high ping scenario for any custom prediction action, you'll have issues......... Right, yeah this is very much game dependent, and an extreme edge case, hahaha.

Although it should be stipulated that this initialisation is server only, at least at a conceptual level. I'll work towards that and when I'll have a solution I'll PR it.

@alirezaka80
Copy link

hi I make own ability system component and Initialize with PossessedBy and OnRep_PlayerState but when use GiveAbility function
ABILITY_LOG(Error, TEXT("GiveAbility called on ability %s on the client, not allowed!"), *Spec.Ability->GetName()) i have this log and because of IsOwnerActorAuthoritative is true how too fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants