Reputation: 1
Using Visual Studio. We would like to implement health and mana through the ATTRIBUTE_ACCESSORS macro in Unreal Engine 5. It is said that a macro can be defined and used to use ATTRIBUTE_ACCESSORS, but even though it is defined, an error occurs that there is no function definition in the line containing ATTRIBUTE_ACCESSORS(UAuraAttributeSet, Data).
// AttributeSet.h
// Copyright Min Creater
#pragma once
#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "AuraAttributeSet.generated.h"
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
/**
*
*/
UCLASS()
class AURA_API UAuraAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
UAuraAttributeSet(); //속성
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Health, Category = "Vital Attributes")
FGameplayAttributeData Health; //체력
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, Health);
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxHealth, Category = "Vital Attributes")
FGameplayAttributeData MaxHealth;
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, MaxHealth);
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Mana, Category = "Vital Attributes")
FGameplayAttributeData Mana; //마나
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, Mana);
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxMana, Category = "Vital Attributes")
FGameplayAttributeData MaxMana;
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, MaxMana);
//BluepritnReadOnly - 엔진 내 블루프린트로 접근
/*
* 새 속성을 추가하기 위한 단계.
* 1. 변수 선언(OnRep_Health), 복제, 담당자 정의(UFUNCTION)
* 2. 이를 정의하고 알림 매크로(cpp. GAMEPLAYATTRIBUTE_REPNOTIFY) 추가
* 3. 복제 변수를 추가하여(DOREPLIFETIME_CONDITION_NOTIFY, 조건 없음) 복제 값을 얻음
*
* 이러한 모든 단계를 Attribute를 사용하고 추가하기 위한 상용구로 칭함.
* 속성이 필요한 모든 작업에는 이와 같은 상용구 단계를 따라야 한다.
*/
UFUNCTION()
void OnRep_Health(const FGameplayAttributeData& OldHealth) const;
UFUNCTION()
void OnRep_MaxHealth(const FGameplayAttributeData& OldMaxHealth) const;
UFUNCTION()
void OnRep_Mana(const FGameplayAttributeData& OldMana) const;
UFUNCTION()
void OnRep_MaxMana(const FGameplayAttributeData& OldMaxMana) const;
};
// AttributeSet.cpp
// Copyright Min Creater
#include "AbilitySystem/AuraAttributeSet.h"
#include "Net/UnrealNetwork.h"
UAuraAttributeSet::UAuraAttributeSet()
{
InitHealth(100.f);
InitMaxHealth(100.f);
InitMana(50.f);
InitMaxMana(50.f);
}
void UAuraAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_CONDITION_NOTIFY(UAuraAttributeSet, Health, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UAuraAttributeSet, MaxHealth, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UAuraAttributeSet, Mana, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UAuraAttributeSet, MaxMana, COND_None, REPNOTIFY_Always);
//복제하려는 모든 항목에 필요한 복제할 상태를 등록, 아무 조건 없이.
}
void UAuraAttributeSet::OnRep_Health(const FGameplayAttributeData& OldHealth) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UAuraAttributeSet, Health, OldHealth);
}
void UAuraAttributeSet::OnRep_MaxHealth(const FGameplayAttributeData& OldMaxHealth) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UAuraAttributeSet, MaxHealth, OldMaxHealth);
}
void UAuraAttributeSet::OnRep_Mana(const FGameplayAttributeData& OldMana) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UAuraAttributeSet, Mana, OldMana);
}
void UAuraAttributeSet::OnRep_MaxMana(const FGameplayAttributeData& OldMaxMana) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UAuraAttributeSet, MaxMana, OldMaxMana);
}
// Build.cs
// Copyright Min Creater
using UnrealBuildTool;
public class Aura : ModuleRules
{
public Aura(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "GameplayAbilities" });
PrivateDependencyModuleNames.AddRange(new string[] { "GameplayTags", "GameplayTasks" , "NavigationSystem", "Niagara", "AIModule" });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}
I rewrote build.cs, rewrote AttributeSet.h, and AttributeSet.cpp files, built it, regenerated the visual studio project, debugged it, and ran the engine in debug mode, but the engine stopped and crashed.
Upvotes: 0
Views: 360
Reputation: 1
Just get solved this right now.
After you've copied macros, you are going to use ATTRIBUTE_ACCESSORS(Attrib_set, StatName)
So just don't put the semicolon at the end, so VS doesn’t take it as a function.
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, Health);
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, Health) // -- like that
Upvotes: 0
Reputation: 1
Ah yes, I as well had this problem, but alas
I've found the answer
https://forums.unrealengine.com/t/gaplay-abities-attributeset-attribute-accessors/451597
Don't type it out, it's a Macro built by Epic and it basically transforms your ability code into something else so copy and paste this directly from the Epic Forums
Then your red squiggly on the A should turn into all green squigglies and you should be all set to go
Upvotes: 0