Hi,
I’m trying to do something pretty simple yet I believe I’m running into a bug with unreal. Basically, I have an InventoryComponent that I’ve made in C++ which has an exposed variable for the capacity of the inventory:
UCLASS(BlueprintType, ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class MY_API UInventoryComponent : public UActorComponent
{
GENERATED_BODY()
private:
// The capacity of the inventory
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
int32 Capacity = 30;
}
Then in my Player.h file I use it like this:
UCLASS()
class MY_API APlayerBase : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
APlayerBase(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "PlayerBase", meta = (AllowPrivateAccess = "true"))
UInventoryComponent* Inventory = nullptr;
}
And in Player.cpp I create it like this:
APlayerBase::APlayerBase(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer)
{
// Create the inventory component
Inventory = CreateDefaultSubobject<UInventoryComponent>("Inventory");
}
Initially it all works great and I can see and edit the capacity in my derived player BP class, but after making changes / recompiling my C++ (I honestly don’t know what causes it) one of two things happen:
- The details panel no longer shows when I click on the component in the editor. I can fix this by either rebasing the player back to a Character and then back to my APlayerBase class or by commenting out the call to CreateDefaultSubobject, compiling, uncommenting it, and compiling again.
- The value I set for Capacity in the blueprint no longer gets applied in C++. It still shows as whatever I set it to in the details panel but in code it is the default value of 30.
This is the bane of my existence currently. If anyone has any idea what I am doing wrong please let me know. Thanks.