This is my Struct declaration. FEquipmentSlot has EquipmentClass and EquipmentCategory these two members, which store the item class and item category.
USTRUCT(BlueprintType)
struct FEquipmentSlot
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<class APickupItem> EquipmentClass;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
PickupItemCategory EquipmentCategory;
FEquipmentSlot() : EquipmentClass(), EquipmentCategory(PickupItemCategory::ABILITY) {}
FEquipmentSlot(TSubclassOf<APickupItem> Class, PickupItemCategory Category)
{
EquipmentClass = Class;
EquipmentCategory = Category;
}
};
And this is my function, I want to construct a struct by passed parameters and add it to TArray
void UEquipmentComponent::AddEquipmentSlot(TSubclassOf<APickupItem> Class, PickupItemCategory Category)
{
//EquipmentSlots is declared as TArray<FEquipmentSlot> type
EquipmentSlots.Add(FEquipmentSlot(Class, Category));
UE_LOG(LogTemp, Warning, TEXT("Add Equipment Slot Success"))
}
Then I call this function like this
AddEquipmentSlot(this->StaticClass(), Category);
Editor will crash, and this is error message
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x000000c8
I'm new to UE4 c++, and I search many answers but seems there is no right answer for this problem. Can anybody help me? Any suggestion will be very helpful.
User contributions licensed under CC BY-SA 3.0