# Inheriting from UCommonSessionSubsystem

**URL:** <https://forums.unrealengine.com/t/inheriting-from-ucommonsessionsubsystem/2666872>\
**Category:** Multiplayer & Networking\
**Tags:** online-session, sessions, unreal-engine, epic-online-services, bug-report, CPP, question\
**Created:** [October 20, 2025, 10:27am UTC](https://forums.unrealengine.com/t/inheriting-from-ucommonsessionsubsystem/2666872 "2025-10-20T10:27:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kirsten](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kirsten](https://forums.unrealengine.com/u/Kirsten)\
**Post date:** [October 20, 2025, 10:27am UTC](https://forums.unrealengine.com/t/inheriting-from-ucommonsessionsubsystem/2666872/1 "2025-10-20T10:27:37Z")

</div>

Hej, we implemented our own UMyUserBasicPresence and UMySessionSubsystem by inheriting from UCommonUserBasicPresence and UCommonSessionSubsystem. The problem is that there seems to be an issue with returning a child class via SubsystemCollection. It doesn’t find the parent if child class is in the list. We are running into the ensure condition, when common presence is trying to access the CommonSessionSubsystem.

```cpp
void UMyUserBasicPresence::Initialize(FSubsystemCollectionBase& Collection)
{
	UMySessionSubsystem* MySessionSubsystem = Collection.InitializeDependency<UMySessionSubsystem>();
	check(MySessionSubsystem ); // Is there another child type of this instance? Check ShouldCreateSubsystem()

	Super::Initialize(Collection);
}

```

Engine\Plugins\Epic\CommonUser\Source\CommonUser\Private\CommonUserBasicPresence.cpp

```cpp
void UCommonUserBasicPresence::Initialize(FSubsystemCollectionBase& Collection)
{
	UCommonSessionSubsystem* CommonSession = Collection.InitializeDependency<UCommonSessionSubsystem>();
	if(ensure(CommonSession)) // <-- THIS IS THE ISSUE, because it's NULL
	{
		CommonSession->OnSessionInformationChangedEvent.AddUObject(this, &UCommonUserBasicPresence::OnNotifySessionInformationChanged);
	}
}

```

CommonSession in the above case is a nullptr. I did a divergency fix on our end, but would like to get some feedback or ask for a real fix.

Engine/Source/Runtime/Engine/Private/Subsystems/SubsystemCollection.cpp

```cpp
void FSubsystemCollectionBase::Initialize(UObject* NewOuter)
{
	if (BaseType->IsChildOf(UDynamicSubsystem::StaticClass()))
		{
            ...
		}
		else
		{
			TArray<UClass*> SubsystemClasses;
			GetDerivedClasses(BaseType, SubsystemClasses, true);

			for (UClass* SubsystemClass : SubsystemClasses)
			{
// DIVERGENCY BEGIN
				bool bIsFinalOverride = true;
				for (UClass* OtherSubsystemClass : SubsystemClasses)
				{
					if (SubsystemClass != OtherSubsystemClass && OtherSubsystemClass->IsChildOf(SubsystemClass))
					{
						bIsFinalOverride = false;
						break;
					}
				}

				if (bIsFinalOverride)
				{
					AddAndInitializeSubsystem(SubsystemClass);
				}
				else
				{
					UE_LOG(LogSubsystemCollection, Verbose, TEXT("Skip initializing subsystem, because it's not the final override %s"), *GetNameSafe(SubsystemClass));
				}
// DIVERGENCY END
				}
			}
		}

```

edit:  
I am aware of this code in CommonSessionSubsystem

```cpp
bool UCommonSessionSubsystem::ShouldCreateSubsystem(UObject* Outer) const
{
	TArray<UClass*> ChildClasses;
	GetDerivedClasses(GetClass(), ChildClasses, false);

	// Only create an instance if there is not a game-specific subclass
	return ChildClasses.Num() == 0;
}

```

---

<div class="post-metadata">

**Author:** ![Kirsten](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kirsten](https://forums.unrealengine.com/u/Kirsten)\
**Post date:** [October 20, 2025, 10:53am UTC](https://forums.unrealengine.com/t/inheriting-from-ucommonsessionsubsystem/2666872/2 "2025-10-20T10:53:38Z")

</div>

> [@Kirsten](#):
>
> `bool UCommonSessionSubsystem::ShouldCreateSubsystem(UObject* Outer) const`

Instead of the above code, we can also go with that solution. I am not sure which one is the best solution.

```auto

			if (CDO->ShouldCreateSubsystem(Outer))
			{
				...
			}
// DIVERGENCY BEGIN
			else
			{
				TArray<UClass*> ChildClasses;
				GetDerivedClasses(SubsystemClass, ChildClasses, false);

				for (auto ChildClass : ChildClasses)
				{
					if (SubsystemMap.Contains(ChildClass))
					{
						UE_LOG(LogSubsystemCollection, VeryVerbose, TEXT("Subsystem does not exist, but CDO choose to not create (%s). Returning ChildClass instead"), *ChildClass->GetName());
						return SubsystemMap.FindRef(ChildClass);
					}
				}				
			}
// DIV END

```
