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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

C++ / Is there a way to draw debug text on the screen at a 3d coordinate?

A lot of other engines have simple functionality to do this built in (as it is extremely useful for debugging), but I haven't been able to find an easy way to do it in UE4.

All I really want to do is draw the index of my route data's nodes at the node position in 3D when the route is selected in the editor. (in both edit and play mode)

I was using a trick posted in the following thread, and managed to create a component that can draw debug primitives while in edit mode. https://answers.unrealengine.com/questions/110338/request-draw-editor-event-for-blueprints-and-nativ.html

However, the only arguments I have in this function are (const FSceneView* View, FPrimitiveDrawInterface* PDI). If I can get a Canvas, it looks like I can at least call DrawText, but trying the following was just making the editor crash somewhere deep in DrawText.

              static const FName CanvasName(TEXT("CanvasObject"));
              UCanvas* Canvas = (UCanvas*)StaticFindObjectFast(UCanvas::StaticClass(), GetTransientPackage(), CanvasName);
 
             if (Canvas)
             {
                 Canvas->SetDrawColor(255, 255, 255);
                 UFont* RenderFont = GEngine->GetSmallFont();
                 const FVector ScreenLocation = Canvas->Project(pos);
                 Canvas->DrawText(RenderFont, FString::Printf(TEXT("%d"), i), ScreenLocation.X, ScreenLocation.Y);
             }

I also tried (experimentally) creating a canvas if it doesn't exist like certain parts of the engine are doing, but it crashed in the same place.

Is there a correct way to get the current canvas somehow, or a better way to draw debug text on the screen?

Also, if any Epic devs are reading this: Please implement easy debug primitive and 2d/3d text printing functions that can be called from anywhere. A huge number of people would benefit from this.

Product Version: Not Selected
Tags:
more ▼

asked Mar 24 '15 at 02:47 PM in C++ Programming

avatar image

mpxc
91 8 12 16

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

3 answers: sort voted first

I was actually referring to a way to do this from C++, sorry my question was unclear.

However, when I tried copying the C++ code the blueprint version of DrawDebugString was using, it functioned perfectly! Problem solved. Thanks!

Sample code:

 #if !UE_BUILD_SHIPPING
        FVector drawPos(0.0f);
        FColor drawColor = FLinearColor(1.0f, 1.0f, 1.0f, 1.0f).ToFColor(true);
        float drawDuration = 0.0f;
        bool drawShadow = true;
        DrawDebugString(GEngine->GetWorldFromContextObject(this), drawPos, *FString::Printf(TEXT("%s[%d]"), TEXT("test"), 12345), NULL, drawColor, drawDuration, drawShadow);
 #endif //!UE_BUILD_SHIPPING


more ▼

answered Oct 06 '16 at 07:15 AM

avatar image

mpxc
91 8 12 16

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

You're looking for DrawDebugString. You can either give it a world position or you can give it an actor reference and the position will instead be used as an offset from that actor. The offset is not affected by the rotation of the actor.

https://docs.unrealengine.com/latest/INT/BlueprintAPI/Rendering/Debug/DrawDebugString/index.html

more ▼

answered Oct 05 '16 at 02:54 PM

avatar image

ddbrown30
238 11 23 104

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

I took a look at the code, when I came across the same problem. The way to do it is to override the virtual void DisplayDebug(UCanvas* Canvas, const FDebugDisplayInfo& DebugDisplay, float& YL, float& YPos); in you pawn or actor code.

Hope that helped!

more ▼

answered May 20 '15 at 04:28 PM

avatar image

kishoreven
302 13 13 25

avatar image kishoreven May 20 '15 at 05:40 PM

Also I am not sure if that really draws a 3D text. So I am at a loss as well :(

(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