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

Adding and removing AttributeSets has problems #16

Closed
ErenBalatkan opened this issue Feb 1, 2020 · 1 comment
Closed

Adding and removing AttributeSets has problems #16

ErenBalatkan opened this issue Feb 1, 2020 · 1 comment

Comments

@ErenBalatkan
Copy link

ErenBalatkan commented Feb 1, 2020

I have a Character and Weapon classes in my project.

Weapon keeps its stats, such as MagazineAmmoCount on an attributeset that it owns. My "shoot" ability costs "1 MagazineAmmoCount" attribute to shoot. However, because these attributes are not initialized properly and instead I add them through SpawnedAttributes.AddUnique (as shown in this documentation), system crashes somewhere and my project closes.

Crash tells me that faulty line is following
UFUNCTION() void OnRep_MagazineAmmoCount() { GAMEPLAYATTRIBUTE_REPNOTIFY(UZWeaponAttributeSet, MagazineAmmoCount); }

I have come up with following solution to work around this problem:
AbilitySystem->InitStats(UZWeaponAttributeSet::StaticClass(), Weapon->StatInitializer); Weapon->InitializeAttributesFromThis(AbilitySystem);

Idea is to basically initialize attributes as standard, and then updating them manually using attribute set located at weapon. I havent tested the unequip function yet.

@tranek
Copy link
Owner

tranek commented Feb 4, 2020

I've actually concluded that using separate AttributeSets on weapons is not a great idea. The main issues are that changes to an Attribute from a GE must go through an ASC and we can't target a specific AttributeSet if more than one of the same class exists on the ASC or the AttributeSet is removed from the ASC but still valid in the world. This causes:

  1. Complications with multiple weapons in your inventory.

  2. If you remove an AttributeSet before an Attribute aggregator change is replicated, the replicated change will not find its AttributeSet and crash the game. I ran into this with a rocket launcher killing myself and removing the AttributeSet on Unequip/Death before the ammo change replication came in.

There are probably ways around these issues, but I find it was much easier just to use replicated raw floats on the weapons for magazine ammo with an Ammo AttributeSet on the Character for reserve ammo (this allows weapons to share reserve ammo of the same ammo type). I'm led to believe that Fortnite also does its ammo this way with raw floats on the weapons (I'm unsure about their reserve ammo).

My next sample project coming soon is an advanced FPS that shows this functionality and how to work with it in GameplayAbilities. I'll update the README when its released.

@tranek tranek closed this as completed Feb 9, 2020
wjh1461 pushed a commit to wjh1461/GASDocumentation that referenced this issue Apr 20, 2023
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

No branches or pull requests

2 participants