관리 메뉴

Mini

[UE5] GE로 속성 초기화하기 // Cast of nullptr to AuraAttributeSet failed 해결 본문

UE5/RPG Attributes

[UE5] GE로 속성 초기화하기 // Cast of nullptr to AuraAttributeSet failed 해결

Mini_96 2024. 6. 6. 23:58

1. GE클래스로 속성초기화하는 함수 생성

DefaultPrimaryAttributes변수가 그 GE임, BP에서 의존성 주입함

class UGameplayEffect;

UCLASS(Abstract)
class AURA_API AAuraCharacterBase : public ACharacter, public IAbilitySystemInterface
@@ -32,4 +33,9 @@ class AURA_API AAuraCharacterBase : public ACharacter, public IAbilitySystemInte
	TObjectPtr<UAttributeSet> AttributeSet;

	virtual void InitAbilityActorInfo();

	UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Attributes")
	TSubclassOf<UGameplayEffect> DefaultPrimaryAttributes;

	void InitializePrimaryAttributes() const;
void AAuraCharacterBase::InitializePrimaryAttributes() const
{
	check(IsValid(GetAbilitySystemComponent())); //ASC확인
	check(DefaultPrimaryAttributes); //GE확인
	//1. Context Handle 만들기
	const FGameplayEffectContextHandle ContextHandle = GetAbilitySystemComponent()->MakeEffectContext();
	//2. Effect Spec 만들기
	const FGameplayEffectSpecHandle SpecHandle = GetAbilitySystemComponent()->MakeOutgoingSpec(DefaultPrimaryAttributes, 1.f,ContextHandle);
	GetAbilitySystemComponent()->ApplyGameplayEffectSpecToTarget(*SpecHandle.Data.Get(), GetAbilitySystemComponent());
}

 

2. 상속받은 아우라캐릭에 위에서 만든 부모함수넣기

위치 : 아래 4개가 모두 유효한 여기 넣는게 바람직함.

AuraPlayerController, AuraPlayerState, AbilitySystemComponent, AttributeSet
/ 능력 시스템 액터 정보를 초기화하는 함수
void AAuraCharacter::InitAbilityActorInfo()
{
	...
	InitializePrimaryAttributes(); //부모의함수
}

 

3. BP에 GE생성

힘을 10으로 초기화함

4. DefaultPrimaryAttributes에 의존성주입(내가만든 GE로)

 

5. 결과

 

* Cast of nullptr to AuraAttributeSet failed 해결

BP_PS에서 뭔가 잘못건드린것같다.

PS를 삭제하고 다시 만드니까 해결됬다..

AuraPS 상속받은 BP 다시만듬

 

https://github.com/DongHoonYu96/GameplayAbilitySystem_Aura/commit/ca3f80ce52c11ecaa060447ed22390f365843e1c

 

feat : GE로 속성초기화 구현 · DongHoonYu96/GameplayAbilitySystem_Aura@ca3f80c

Bisu96 committed Jun 6, 2024

github.com