Check if Blueprint is being run within the editor (i.e if WITH_EDITOR in C++)

It’s not my plugin, but I can’t live without it. you can use it in blueprints only projects, otherwise I would not have put it as a solution :joy:. The plugin exposes a lot of usable c++ functions.
image

well if you do blueprints, you’re a developper

1 Like

I know this is a blueprint question but with a few C++ lines you can get very precise results, see here How to check if game is running - #12 by tuatec. Maybe someone will find this useful as well, it took me quite some time to figure this out. :wink:

Another thing that seems to work is

static bool isEditorBuild()
{
#ifdef UE_EDITOR_BUILD
return true;
#else
return false;
#endif
}

1 Like

To add to this, the complete code for this would be (for UE5 and onward):

Assuming you’ve made a header file named “CommonUtilsBlueprintLibrary”, this would work out of the box and provide you with a globally callable BP function named “RunningInPIE”.

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CommonUtilsBlueprintLibrary.generated.h"

/**
 *
 */
UCLASS()
class UCommonUtilsBlueprintLibrary: public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

	//! Allow the blueprint to determine whether we are running with the editor or not
	UFUNCTION(BlueprintPure, BlueprintCallable, Category = "CommonUtilsFunctionLibrary")
	static bool RunningInPIE()
        #if WITH_EDITOR
            return true;
        #else
            return false;
        #endif
};
	
};
3 Likes

The question is clearly about pure vanilla BP VM, the C++ code posted has no relevance. And while there are no 100% way to check it in vanilla, we have workarounds:

2 Likes

Brilliant, this post can already be resolved by the OP. The ultimate workaround :clap:

Thanks a lot ! And With this tutorial video solve my problem【WTF Is? Is Packaged For Distribution in Unreal Engine 4 ( UE4 ) - YouTube

Holy crap what a plugin, thanks for sharingĄ

1 Like

Is there a better way in C++? WITH_EDITOR is not enough

Not enough how? You can’t possible package standalone runtime for distribution WITH_EDITOR enabled. You gonna have to rewrite and fix a LOT of things. Not even mentioning you are not allowed to redistribute EDITOR stuff.
So it is more than enough.

Not fond of the “hack” way you are using with UEDPIE. It’s not for packing, it is for detecting whether it is running in animation/particle editor or other editor window other than PIE.

Программирую для андроид. Мне помогает (if “Get Platform Name” == Windows)

Can you use [Get Game Mode] → [Is Valid ?] ? It will return null if in the editor and if in game non null :slight_smile:

1 Like

I know it’s not the answer for the exact question of the OP, but it’s somehow related:

Without any plugins, in out of the box UE, you can use this node:
image

#if UE_BUILD_DEBUG
  return EBuildConfiguration::Debug;

#elif UE_BUILD_DEVELOPMENT
  return bIsDebugGame ? EBuildConfiguration::DebugGame : EBuildConfiguration::Development;

#elif UE_BUILD_SHIPPING
  return EBuildConfiguration::Shipping;

#elif UE_BUILD_TEST
  return EBuildConfiguration::Test;

#else
  return EBuildConfiguration::Unknown;

#endif

It will return one of: Debug, Development, Shipping, Test or Unknown and you can react to the value of this string accordingly.

It’s more granular than IsPackagedForDistribution node but doesn’t require third party wonky plugins to be installed.

I believe this is the definitive answer based on everything that has been posted.
One is used to know if you have pressed play in the editor and the other is used to know if you are in the editor but not in play.

1 Like