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"

How can I make UFUNCTION(exec) work inside #if !UE_BUILD_SHIPPING?

Hello!--

I would like to have a debug function as follows:

 #if !UE_BUILD_SHIPPING

     bool DebugEnabled;

     /* Enables Debug */
     UFUNCTION(Exec)
     void ShowMyDebug(bool param);

  #endif

However, it seems that the Exec does not persist when written in this way. The function and variable are created and may be called upon at runtime. If I comment out the preprocesser lines, the function does properly show up in the console.

I am doing this to create very simple debug functionality that can be run in the editor or in a normal development runtime build that is not "SHIP"

Any tips or suggestions to solve this would be much appreciated!

Thanks, J

Product Version: Not Selected
Tags:
more ▼

asked Jun 05 '14 at 03:09 AM in C++ Programming

avatar image

JDizzleSTiX
63 2 6 9

avatar image Shadowriver Jun 05 '14 at 09:19 PM

To understand this problem you need to understand that U-macros (UFUNCTION, UCLASS etc.) are only used by Unreal Header Tool (UHT) which based on those generates header files which allows engine to see class structure and those macros are ignored during compile time.

I heard that UHT has problems parsing other C++ preprocessing calls so that might be the cause :p

avatar image JDizzleSTiX Jun 06 '14 at 03:05 AM

Ahh, thanks for the insight! I assumed it was something like this.

Any known workaround or fix?

avatar image exAntares Jul 16 '14 at 11:27 AM

Maybe you could just do the same thing but inside the .cpp so the function altho it still exec, only does nothing when shipping

 void MyClass::ShowMyDebug(bool param)
 {
    #if !UE_BUILD_SHIPPING
     //Code here
    #endif
 }

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

1 answer: sort voted first

We had the same problem on our project. I found that using the existing UCheatManager system makes adding debug functions rather easy.

First, extend UCheatManager in your own class:

 UCLASS()
 class UMyCheatManager : public UCheatManager
 {
     GENERATED_BODY()
 public:
 
     UFUNCTION(exec)
     void MyDebugFunction();
 };

Then, implement it in the constructor of your player controller class:

 AMyPlayerController::AMyPlayerController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
 {
     CheatClass = UMyCheatManager::StaticClass();
     ...
 }

The APlayerController class has the code for enabling and disabling cheats (debug functions) based on build type and gamemode settings.

more ▼

answered Jan 13 '16 at 12:58 AM

avatar image

ZakBlystone
126 3 6 11

(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