Automation Tests using Subsystem

Hello,

I want to write tests to test a subsystem, but I couldn’t find a way of creating the subsystem in the test scope. CreateNew doesn’t work and I don’t know how to even get the game instance so I can access it. And I also would prefer that I could access the subsystem directly instead of having to access the game instance to get it.

Do you know how or If I can achieve this?

I know that

Thank you,

Hello,

In order to access a subsystem from an automated test, you first have to construct a game instance which will create the subsystem. Use the following code:

UMySubsystem* MySubsystemRef = NewObject<UGameInstance>()->GetSubsystem<UMySubsystem>();

This will create a gameinstance and get the subsystem from it. You may set the game instance to be your production game instance, or just use UGameInstance as that will create the subsystems the same way.

Hope this helps,
Patrick

2 Likes

Extra note: you may have to call Init() on the new game instance before calling GetSubsystem. At least I had to when I tried this.
UGameInstance* GameInstance = NewObject();
GameInstance->Init();
UMySubsystem* manager = GameInstance->GetSubsystem();

Before calling Init the subsystem map was empty.

4 Likes