# New non UCLASS crashes on Simulate Play

**URL:** <https://forums.unrealengine.com/t/new-non-uclass-crashes-on-simulate-play/385719>\
**Category:** Platform & Builds\
**Tags:** steamworks, crash-on-play, unreal-engine, crash, CPP, question\
**Created:** [February 21, 2017, 10:00pm UTC](https://forums.unrealengine.com/t/new-non-uclass-crashes-on-simulate-play/385719 "2017-02-21T22:00:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Motanum](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Motanum](https://forums.unrealengine.com/u/Motanum)\
**Post date:** [February 21, 2017, 10:00pm UTC](https://forums.unrealengine.com/t/new-non-uclass-crashes-on-simulate-play/385719/1 "2017-02-21T22:00:58Z")

</div>

Hello,

I am trying to implement STEAM\_CALLBACK() macro in my game. I found out that you cannot use the macro with a UCLASS, as it would fail to compile and cause a bunch of errors. So my solution was to have one UCLASS ,which the game reads, and is a inheritance game instance. And then a new non UCLASS which is used to retrieve Steam callbacks and then fire up the game instance’s events. As a very basic start, I just want to detect the Steam Game Overlay, and if it’s enabled, pause the game.

The code below compiles just fine, but the problem I am running into, is that the editor will crash when I start “Simulate” play. And I don’t know why it does that. These changes are the only thing being worked on. It didn’t crash at all before I added the new class FSteamworksCallbackAsync, so I think that the issue is there, but I don’t know why it’s doing that. I tried adding SteamAPI\_Init() check, and checking to be sure that the class does have a GameInstance that is of type UMusicalRangeInstance, but I have no luck.

I appreciate any help!

The header File

```
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "ThirdParty/Steamworks/Steamv132/sdk/public/steam/steam_api.h"
#include "Engine/GameInstance.h"
#include "MusicalRangeInstance.generated.h"

/**
 * 
 */
UCLASS()
class MUSICALRANGE_API UMusicalRangeInstance : public UGameInstance
{
	GENERATED_BODY()

private:

public:
	/* test the functionality of the Game Instance */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Game Instance")
	int32 InterLevelPersitentValue;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Steamworks")
	bool IsSteamOverlayActive;

	UFUNCTION(BlueprintCallable, category = "Game Instance")
	bool InterLevelPersitentValuePONE();
	
	/*
	* Must be called every frame so callbacks can be received
	* Always Return True!
	*/
	UFUNCTION(BlueprintCallable, category = "Steamworks")
	bool RunSteamCallbacks();

	UFUNCTION(BlueprintImplementableEvent, Category = "Steamworks")
	void OnSteamOverlayIsActive(bool isOverlayActive);

	void SteamOverlayActive();
		
	void OnSteamOverlayEnabled(GameOverlayActivated_t *pResult, bool bIOFailure);
	CCallResult<UMusicalRangeInstance, GameOverlayActivated_t> m_callResultGameOverlayActive;
};

/*
*
*/
class MUSICALRANGE_API FSteamworksCallbackAsync
{

private:
	STEAM_CALLBACK(FSteamworksCallbackAsync, OnSteamOverlayActive, GameOverlayActivated_t, OnSteamOverlayActiveCallback);

public:
	//Constructors
	FSteamworksCallbackAsync();
	~FSteamworksCallbackAsync();

	UMusicalRangeInstance *MusicalRangeGameInstance;

};

```

The CPP File  
// Fill out your copyright notice in the Description page of Project Settings.

```
#include "MusicalRange.h"
#include "MusicalRangeInstance.h"

//Musical Range Game Instance Elements
bool UMusicalRangeInstance::InterLevelPersitentValuePONE() {
	InterLevelPersitentValue++;
	return true;
}

bool UMusicalRangeInstance::RunSteamCallbacks() {
	SteamAPI_RunCallbacks();
	SteamOverlayActive(); //Check for active overlay
	return true;
}

void UMusicalRangeInstance::SteamOverlayActive() {
	SteamAPICall_t hSteamAPICall = SteamUtils()->IsOverlayEnabled();
	m_callResultGameOverlayActive.Set(hSteamAPICall, this, &UMusicalRangeInstance::OnSteamOverlayEnabled);
	return;
}

void UMusicalRangeInstance::OnSteamOverlayEnabled(GameOverlayActivated_t *pResult, bool bIOFailure) {
	IsSteamOverlayActive = (pResult->m_bActive != 0);
	OnSteamOverlayIsActive(IsSteamOverlayActive);
	return;
}

//FSteamworksCallbackAsync elements
FSteamworksCallbackAsync::FSteamworksCallbackAsync() :
	OnSteamOverlayActiveCallback(this, &FSteamworksCallbackAsync::OnSteamOverlayActive)
{
	if (SteamAPI_Init() && GEngine->GetWorld() != nullptr && GEngine->GetWorld()->GetGameInstance() != nullptr)
	{
		MusicalRangeGameInstance = Cast<UMusicalRangeInstance>(GEngine->GetWorld()->GetGameInstance());
	}
}

FSteamworksCallbackAsync::~FSteamworksCallbackAsync() {

}

void FSteamworksCallbackAsync::OnSteamOverlayActive(GameOverlayActivated_t *CallbackData) {
	if (SteamAPI_Init())
	{
		bool IsOverlayActive = (CallbackData->m_bActive != 0);
		GEngine->AddOnScreenDebugMessage(-1, 15, FColor::Cyan, IsOverlayActive ? "Overlay is ACTIVE" : "Overlay is OFF");
		MusicalRangeGameInstance->OnSteamOverlayIsActive(IsOverlayActive);
	} else {
		GEngine->AddOnScreenDebugMessage(-1, 15, FColor::Red, "Error with SteamAPI" );
	}

}
```

---

<div class="post-metadata">

**Author:** ![Motanum](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Motanum](https://forums.unrealengine.com/u/Motanum)\
**Post date:** [February 22, 2017, 5:38pm UTC](https://forums.unrealengine.com/t/new-non-uclass-crashes-on-simulate-play/385719/2 "2017-02-22T17:38:00Z")

</div>

It turns out that the issue was not the new class. Instead, I was calling

```
bool UMusicalRangeInstance::RunSteamCallbacks()

```

every frame, and after removing it, it didn’t crash on start simulating play. The crash happened by calling SteamOverlayActive() under RunSteamCallbacks().

I took out that function and it ran okay. The crash is no longer happening.

I think I have to do some SteamAPI\_Init() checks to prevent from crashing.
