Hello!
I’m building a Command Pattern for a game I’m working on. Most of the things are working fine, but now I’m stuck on accessing my UCommandSubsystem
that extends ULocalPlayerSubsystem
from Blueprints. Here is the inheritance:
ULocalPlayerSubsystem -> UCommandSubsystem
UObject -> UCommand -> BP_TestCommand
What I’m trying to do is have the base classes defined in C++, but the concrete Commands in Blueprints for the ease of scripting. However, my BP_TestCommand refuses to be able to access the UCommandSubsystem
throwing some errors about context (I guess it cannot resolve the local player controller?).
Here is the full code for the examples:
UCommand.h:
UCLASS(abstract, Blueprintable)
class AVA_API UCommand : public UObject
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
void Execute();
};
UCommandSubsystem.h:
UCLASS()
class AVA_API UCommandSubsystem : public ULocalPlayerSubsystem
{
GENERATED_BODY()
public:
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
UFUNCTION(BlueprintCallable)
void Test();
};
UCommandSubsystem.cpp:
void UCommandSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
}
void UCommandSubsystem::Test()
{
UE_LOG(LogTemp, Display, TEXT("COMMAND TEST"));
}
And this is what the blueprint looks like:
It is being called from here:
Unfortunately, this gives me an error and I’m pretty much stuck, I’m not sure why this wouldn’t work:
Blueprint Runtime Error: "Accessed None trying to read property CallFunc_GetLocalPlayerSubSystemFromPlayerController_ReturnValue". Node: Test Graph: EventGraph Function: Execute Ubergraph Test Command Blueprint: BP_TestCommand
I’m basing my code on Introducing the Command Design Pattern in Unreal Engine 4 - YouTube and as you can see in 9:48 he is able to access that subsystem from his commands. He has them implemented in C++ and not in blueprints, though. What am I missing about this? Is it because Blueprint inherits from UObject and doesn’t know which local player to use? How to fix this?