Proper way to get a UWorldSubSystem

I’ve made a UWorldSubSystem child class to hold all the grid positions of my map to do some position verifications for the player movement. But I struggling to get the instance of that class in the player script, all tutorials I’ve found shows only how to get a GameInstance and the way I’m doing is getting me null. Any help?

The SubSystem class

UCLASS(Blueprintable)
class DUNGEONCRAWLER_API UMapGridInstance : public UWorldSubsystem
{
	GENERATED_BODY()

public:
	virtual void Initialize(FSubsystemCollectionBase& Collection) override;

	UFUNCTION(BlueprintCallable)
	void AddNodePosition(ANodePosition * nodePosition);

	UFUNCTION(BlueprintCallable)
	int GetGridSize();
	
	bool CheckForPosition(FVector position);
	class ANodePosition* GetNode(FVector position);
	void SetNeighbours(class ANodePosition*);
	
private:
	TMap<FString, class ANodePosition *> gridPositions;
	TArray<FVector> direction;
};
UMapGridInstance* GameInstanceRef = Cast<UMapGridInstance>(GetOwner()->GetWorld()->GetSubsystem<UWorldSubsystem>());
1 Like

I know it’s been a long time, but the correct way to do this at least as far as I know is:
UMapGridInstance* GameInstanceRef = GetWorld()->GetSubsystem<UMapGridInstance>();
Though… that’s not a game instance it’s an instance of that custom world subsystem. They also have UGameInstanceSubsystem if that’s the life cycle you are looking for and you would get that one with something like this:
UOurGameInstanceSubsystem* gameInstanceSubsystem = GetGameInstance()->GetSubsystem<UOurGameInstanceSubsystem>();