# Automation Tests using Subsystem

**URL:** <https://forums.unrealengine.com/t/automation-tests-using-subsystem/467211>\
**Category:** C++\
**Tags:** automated-testing, subsystem, unreal-engine, question, CPP\
**Created:** [June 24, 2020, 10:26pm UTC](https://forums.unrealengine.com/t/automation-tests-using-subsystem/467211 "2020-06-24T22:26:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lawendt](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lawendt/32/473603_2.png) [@Lawendt](https://forums.unrealengine.com/u/Lawendt)\
**Post date:** [June 24, 2020, 10:26pm UTC](https://forums.unrealengine.com/t/automation-tests-using-subsystem/467211/1 "2020-06-24T22:26:02Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![MutatePat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MutatePat](https://forums.unrealengine.com/u/MutatePat)\
**Post date:** [June 26, 2020, 1:13pm UTC](https://forums.unrealengine.com/t/automation-tests-using-subsystem/467211/2 "2020-06-26T13:13:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a13c1e2f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a13c1e2f](https://forums.unrealengine.com/u/anonymous_user_a13c1e2f)\
**Post date:** [January 15, 2021, 11:49am UTC](https://forums.unrealengine.com/t/automation-tests-using-subsystem/467211/3 "2021-01-15T11:49:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DrDarrenMyatt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DrDarrenMyatt](https://forums.unrealengine.com/u/DrDarrenMyatt)\
**Post date:** [August 6, 2024, 5:04pm UTC](https://forums.unrealengine.com/t/automation-tests-using-subsystem/467211/5 "2024-08-06T17:04:14Z")

</div>

I also found that GameInstance-\>Shutdown() was needed at the end of the test, else something would go horribly wrong when the game instance was garbage collected (related to deinitialising the subsystems).
