# \#if WITH\_EDITOR only removing code from .h, not .cpp

**URL:** <https://forums.unrealengine.com/t/if-with-editor-only-removing-code-from-h-not-cpp/420241>\
**Category:** Platform & Builds\
**Tags:** unreal-engine, Code, Packaging, question, CPP\
**Created:** [March 19, 2018, 12:00pm UTC](https://forums.unrealengine.com/t/if-with-editor-only-removing-code-from-h-not-cpp/420241 "2018-03-19T12:00:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Epok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Epok](https://forums.unrealengine.com/u/Epok)\
**Post date:** [March 19, 2018, 12:00pm UTC](https://forums.unrealengine.com/t/if-with-editor-only-removing-code-from-h-not-cpp/420241/1 "2018-03-19T12:00:57Z")

</div>

Using #if WITH\_EDITOR I have declared a property, that when packaged without the editor, correctly removes itself from the code. However references to that property (also wrapped in #if WITH\_EDITOR) get packaged anyway; resulting in compile errors.

Here is the code:

.h

```
#if WITH_EDITOR

	UPROPERTY(EditAnywhere, Category = "Debug")
	bool DrawDebug = false;

#endif

```

.cpp

```
#if WITH_EDITOR

		if (DrawDebug)
		{
			UE_LOG(LogTemp, Warning, TEXT("Why is this being packaged?"));
		}

#endif

```

Compile error:

```
error C2039: 'DrawDebug': is not a member of 'UBTTask_SetOptimalCoverPose'
```

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [March 19, 2018, 4:09pm UTC](https://forums.unrealengine.com/t/if-with-editor-only-removing-code-from-h-not-cpp/420241/2 "2018-03-19T16:09:59Z")

</div>

Hey.

WITH\_EDITOR doesn’t work with UPROPERTIES/UFUNCTIONS at all (probably same goes for UCLASSes but I haven’t tried that). If you want to compile out a UPROPERTY, you can use WITH\_EDITORONLY\_DATA instead.

Cheers.

---

<div class="post-metadata">

**Author:** ![Epok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Epok](https://forums.unrealengine.com/u/Epok)\
**Post date:** [March 19, 2018, 5:29pm UTC](https://forums.unrealengine.com/t/if-with-editor-only-removing-code-from-h-not-cpp/420241/3 "2018-03-19T17:29:54Z")

</div>

Thank you!

WITH\_EDITOR appears to work for overriden UFUNCTIONs, like PostEditProperties, but swapping to WITH\_EDITORONLY\_DATA for everything else has fixed my build errors.
