Hi,
So I was meaning to create a Weapon slots system for a game I’m working on, and my idea was that I’d have a struct representing a Weapon Slot, which I could just add/attach to the character. This is the first time I have tried using USTRUCTS, and I can’t see to figure out the problem here.
- I created a C++ class with the parent “user defined struct”. This is the .h file for the same:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include “CoreMinimal.h”
#include “PBaseWeapon.h”
#include “Engine/UserDefinedStruct.h”
#include “WeaponSlots.generated.h”
USTRUCT(BlueprintType)
struct FWeaponSlot {
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Details")
bool isEmpty;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Details")
FString WeaponName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Details")
APBaseWeapon* WeaponBP;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Details")
int AmmoCount;
void SetIsEmpty(bool value) {
isEmpty = value;
}
bool GetIsEmpty() {
return isEmpty;
}
// other getter and setter methods here
FWeaponSlot() {
isEmpty = false;
WeaponName = "";
WeaponBP = NULL;
AmmoCount = 0;
}
};
UCLASS()
class PAINTGAME_API UWeaponSlots : public UUserDefinedStruct
{
GENERATED_BODY()
};
This compiles just fine.
Now I added two FWeaponSlot variables on my character called Primary and Secondary Slots. In the character’s BeginPlay function, I do this :
PrimarySlot->SetIsEmpty(true);
SecondarySlot->SetIsEmpty(true);
Even this compiles and gives no errors, but as soon as I hit play, i.e. as soon as the character’s BeginPlay is executed, the editor crashes.
Any suggestion or a nudge in the right direction as to why this is happening or how to go about using Structs, is greatly appreciated.
Thanks!