Hiya,
So I have set up a struct with a couple of properties. I’ve setup the the UPROPERTY, but when I make a struct in a blueprint editor, the whole editor crashes.
It crashes when ever I try and pick a class for the InventoryItemClass drop down.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "InventoryItemBase.h"
#include "InventoryComponent.generated.h"
USTRUCT(BlueprintType)
struct FInventorySlot
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Inventory")
TSubclassOf<AInventoryItemBase> InventoryItemClass;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Inventory")
int32 Count;
};
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class UE_HDGAME_API UInventoryComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UInventoryComponent();
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
// Add an inventory item to players inventory. Returns the index in the inventory
UFUNCTION(BlueprintCallable, Category = "Inventory Management")
int32 AddItem(FInventorySlot InventoryItem);
// Returns an array of inventory slots
UFUNCTION(BlueprintPure, Category = "Inventory Management")
TArray<FInventorySlot> GetItems();
// Low level removes the item from the array
UFUNCTION(BlueprintCallable, Category = "Inventory Management")
void RemoveItem(int32 ItemIndex);
// Add an inventory item to players inventory
UFUNCTION(BlueprintCallable, Category = "Inventory Management")
void DropItem(int32 ItemIndex);
// Add an inventory item to players inventory
UFUNCTION(BlueprintCallable, Category = "Inventory Management")
void EquipItem(int32 ItemIndex);
protected:
// Called when the game starts
virtual void BeginPlay() override;
private:
TArray<FInventorySlot> InventoryItems;
};