ActorComponent gets none in blueprint

Hello everyone,

I have written an UInventoryComponent class which inherits from UActorComponent. I register it to my character in its constructor this way:

Inventory = CreateDefaultSubobject<UInventoryComponent>(TEXT("InventoryComponent"));

InventoryComponent.h:

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Item.h"
#include "InventoryItem.h"
#include "InventoryComponent.generated.h"

class AItemActor;

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RPS_API UInventoryComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UInventoryComponent();
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory")
	TArray<UInventoryItem*> items;

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	UFUNCTION(BlueprintCallable)
		void AddItemActor(AItemActor * itemActor);
	UFUNCTION(BlueprintCallable)
	void AddItem(TSubclassOf<UItem> item,int number=1);
	UFUNCTION(BlueprintCallable)
	void DropItem(UInventoryItem *iItem);

	UFUNCTION(BlueprintCallable)
		void RemoveItem(UItem *item);
	UFUNCTION(BlueprintCallable)
		TArray<UInventoryItem*> GetItems(TSubclassOf<UItem> item);
	UFUNCTION(BlueprintCallable)
		int GetItemCount(TSubclassOf<UItem> item);
	UFUNCTION(BlueprintCallable)
		bool HasItem(TSubclassOf<UItem> item);
};

however, when I restart the engine or change my characters c++ class, this Inventory component becomes None in blueprint. It throws error when I try to use it.

The solution I found was to remove the CreateDefaultSubObject line, then compile, then re-add the line again, and compile, and everything works fine. This, as you notice, is a boring process and I believe this is not the expected behavior of the engine. If I add the component from blueprint (not from c++ constructor) I never have any problem.

What may be the solution?
Thanks

I had kind of same issue about overlap/hit events. I think, this is about hot reload. I couldn’t find any solution, however, the user “NoCodeBugsFree” suggested that re-parenting BP class to another class and then going back to the original class solves the issue sometimes. So, it looks like there is no solution. When it happens, closing and reopening editor should solve the issue.

Here is my similar issue:

Did you created blueprint of your character class, or c++ version?

I noticed an issue in blueprints, inherited from custom c++ classes, that when you add/change something to its constructor, you must recreate blueprint asset. It seems that blueprint is not updated with new changes So, I fixed it with not creating blueprints from that classes at all, or creating them only when I sure that it finished.