I have tried to read about when to use it, or the difference between both, UE_BUILD_SHIPPING vs WITH_EDITOR
, but I am still so confused. could you plz explain it in simple way.
also I have the following questions:
1- if I have a code that supposed to run only with the build aimed for shipping, what should I use?
for example code to confirm that game running through steam
2- if I have a code that supposed to run only when game running through editor, what should I use?
for example, text label appear above actors
3- is the follow example using it in the right way?
//! Allow the blueprint to determine whether we are running with the editor or not
UFUNCTION( BlueprintPure, Category = Whatever )
bool IsWithEditor() const
{
#if WITH_EDITOR
return true;
#else
return false;
#endif
}
UE_BUILD_SHIPPING - is defined when code is compiled during packaging for shipping build. Usually used with negation to isolate debug code, so it wont be compiled in shipping build
WITH_EDITOR - if you compile code that be used in editor build of engine (Editor API available). Used usually to isolate code that uses editor APIs so you wont get compilation error on packaging.
Note that this is only preprocessing and only apply compile time. WITH_EDITOR does not guaranty that code will always run in editor, as you can play project without editor or packaging (right click uproject and launch game").
For runtime check you should use GIsEditor global variable instead