x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Does UE4 have compile-time constants?

I was wondering, is there any way to determine at compile time if we're running in the UE4 editor, or in a packaged game? Is there some sort of compile-time constant defined by UE4's build system like UE4_EDITOR so that I can write

 #ifdef UE4_EDITOR
     do_stuff();
 #endif
Product Version: UE 4.19
Tags:
more ▼

asked Jan 21 '19 at 06:45 PM in C++ Programming

avatar image

Michael Ala
1 1 1

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Yup..

 #if WITH_EDITOR
  do_stuff();
 #endif
 
 #if WITH_EDITORONLY_DATA
   do_stuff();
 #endif

Difference between WITH_EDITOR and WITH_EDITORONLY_DATA is this:

WITH_EDITOR: used to exclude complete functions (declaration and definition) in packaged games. Mostly used for EDITOR functions which cause compile errors in packaged game where you dont have editor module :)

WITH_EDITORONLY_DATA: used to mark things inside the scope and inside the function (you cant exclude complete functions, but you can exclude different things inside the function)

for example:

 .h
 
 #if WITH_EDITOR
 void EditorFunction();
 #endif
 
 .cpp
 
 #if WITH_EDITOR
 void Class::EditorFunction()
 {
      // do something
 }
 #endif
 
 2.
 
 void Class::BeginPlay()
 {
      int32 i = 0;
 
 #if WITH_EDITORONLY_DATA
      i = 1; // be one while we using editor
 #endif
 }

more ▼

answered Jan 22 '19 at 11:12 AM

avatar image

AmphDev
1.4k 15 9 33

avatar image Michael Ala Jan 22 '19 at 02:21 PM

EDIT: This does not work. WITH_EDITORDATA_ONLY seemed to be defined regardless of whether or not I was using the UE4 editor.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question