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 To Make Static Helper Function that Prints Text to the Screen?

Hello. I want to make a static helper library, which prints the text to the game screen. I tried this code but it gives error.

Helper.h:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "UObject/NoExportTypes.h"
 #include "Helper.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class BETHEONE_API UHelper : public UObject
 {
     GENERATED_BODY()
     
     public:
     static void PrintToScreen(FString String);
     
     
 };

Helper.cpp:

 #include "Helper.h"
 
 void PrintToScreeen(FString String)
 {
     if (GEngine) {
         GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::White, *String);
     }
 }
 
 
 

The error: When I try to call the function like UHelper::PrintToScreen(TEXT("Something")); and first including like #include "Helper.h", it gives two errors. First of all, it says identifier "GEngine" is undefined, and second one is just a crash without any trace.

What is the problem? I am using the version 4.20.1.

Product Version: UE 4.20
Tags:
more ▼

asked Aug 16 '18 at 10:17 PM in C++ Programming

avatar image

Sphynxinator
6 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

To fix the “GEngine is undefined” problem, you need to put this in the .h file

#include "Engine.h"

more ▼

answered Aug 17 '18 at 02:03 AM

avatar image

TheApplePieGod
26 2 1 3

avatar image Sphynxinator Aug 17 '18 at 09:43 AM

It fixed the problem. Thanks. But still crashes. :(

avatar image TheApplePieGod Aug 17 '18 at 02:02 PM

Weird. I tested this out myself and it seems to work fine

 void ARTSCharacter::PrintToScreen(FString String)
 {
     if (GEngine)
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *String);
     }
 }
 
 void ARTSCharacter::callstring()
 {
     PrintToScreen("test");
 }

are you calling with a different kind of parameter for the string?

avatar image Sphynxinator Aug 17 '18 at 08:17 PM

No no, I'm calling the method from another class. That's why it's crashing. You called the method from same class.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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