# Wrapping U... macros with preprocessor directives

**URL:** <https://forums.unrealengine.com/t/wrapping-u-macros-with-preprocessor-directives/1277549>\
**Category:** C++\
**Tags:** uht, unreal-engine, question, CPP\
**Created:** [August 30, 2023, 11:22am UTC](https://forums.unrealengine.com/t/wrapping-u-macros-with-preprocessor-directives/1277549 "2023-08-30T11:22:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzemzmcdonalda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dzemzmcdonalda/32/1214680_2.png) [@dzemzmcdonalda](https://forums.unrealengine.com/u/dzemzmcdonalda)\
**Post date:** [August 30, 2023, 11:22am UTC](https://forums.unrealengine.com/t/wrapping-u-macros-with-preprocessor-directives/1277549/1 "2023-08-30T11:22:08Z")

</div>

Hello,

I would like to declare a UPROPERTY that is only accessible in Development builds for debug purposes, e.g:

```auto
#if !UE_BUILD_SHIPPING
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Debug")
	bool bDrawBordersAtRuntime;
#endif //!UE_BUILD_SHIPPING

```

but this throws following UHT error at compile time:

```auto
Error: 'UPROPERTY' must not be inside preprocessor blocks, except for WITH_EDITORONLY_DATA

```

And after looking for this error in source, it seems like all U… macros cannot be wrapped by the preprocesor macro ([UhtTokenBufferReader.cs](https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Programs/Shared/EpicGames.UHT/Tokenizer/UhtTokenBufferReader.cs#L735)):

```auto
if (localValueSpan.CompareTo("UPROPERTY", StringComparison.Ordinal) == 0 ||
	localValueSpan.CompareTo("UCLASS", StringComparison.Ordinal) == 0 ||
	localValueSpan.CompareTo("USTRUCT", StringComparison.Ordinal) == 0 ||
	localValueSpan.CompareTo("UENUM", StringComparison.Ordinal) == 0 ||
	localValueSpan.CompareTo("UINTERFACE", StringComparison.Ordinal) == 0 ||
	localValueSpan.CompareTo("UDELEGATE", StringComparison.Ordinal) == 0 ||
	localValueSpan.CompareTo("UFUNCTION", StringComparison.Ordinal) == 0)
{
	this.LogError($"'{localValueSpan.ToString()}' must not be inside preprocessor blocks, except for WITH_EDITORONLY_DATA");
}

```

This appears to be a pretty big limitation. **What are the reasons for said limitation?**  
As I understand, the whole module can be excluded from the shipping build, so it’s a bit strange that some of the functions/properties cannot be excluded (but there is probably a good reason for that).

**Are there any alternatives that I can use in this case?**

Thanks!

---

<div class="post-metadata">

**Author:** ![dzemzmcdonalda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dzemzmcdonalda/32/1214680_2.png) [@dzemzmcdonalda](https://forums.unrealengine.com/u/dzemzmcdonalda)\
**Post date:** [August 30, 2023, 12:03pm UTC](https://forums.unrealengine.com/t/wrapping-u-macros-with-preprocessor-directives/1277549/2 "2023-08-30T12:03:41Z")

</div>

Okey, after thinking about this problem a bit I started to realize that there is indeed a lot of reasons explaining why this wouldn’t work - e.g. this would break a lot of stuff in Blueprints, and would be generally hard to manage there.

There is a `DevelopmentOnly` meta specifier for UFunction ([ObjectMacros.h](https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h#L1437)):

```auto
/// [PropertyMetadata] For functions that should be compiled in development mode only.
DevelopmentOnly, 

```

So I can probably solve my exact case in the following way:

```auto
#if !UE_BUILD_SHIPPING
	bool bDrawBordersAtRuntime;
#endif //!UE_BUILD_SHIPPING

	UFUNCTION(BlueprintCallable, Category = "Debug", meta = (DevelopmentOnly))
	void SetDrawBordersAtRuntime(bool bNew)
	{
#if !UE_BUILD_SHIPPING
		bDrawBordersAtRuntime = bNew;
#endif //!UE_BUILD_SHIPPING
	}

	UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Debug", meta = (DevelopmentOnly))
	bool GetDrawBordersAtRuntime()
	{
#if !UE_BUILD_SHIPPING
		return bDrawBordersAtRuntime;
#endif //!UE_BUILD_SHIPPING
		return false;
	}

```

Not very elegant but should work just fine.

Leaving my question open in case someone has a better idea.
