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. 

DebugDrawLine() not drawing a visible line

Hi forum, I have an issue with what i feel should be very simple. I cannot get DebugDrawLine() to actually draw a line that i can see. I am calling the function below from within a custom blueprint node if that makes a difference.

 void USwingShot::Draw(const FVector& Start, const FVector& End)
 {
     //TODO: Draw the line we want to check against
     UE_LOG(LogTemp, Warning, TEXT("Drawing Line"));
     // may be able to use the traceline function to also draw the line for this
     DrawDebugLine(
         GetWorld(),
         Start,
         End,
         FColor(255, 255, 255),
         true, // sets weather or not the line is in the world permanently
         -1.f, 0,
         5
     );    
 }

I found that i didn't have DrawDebugHelpers.h originally which i only found out about in a single question on here. however even with that included i still cannot see a line. I have tried giving the line an alpha value of 1 and still nothing. i am wondering if there is a setting i need to torn on like there is in Unity.

Any help is greatly appreciated. Thanks, ND

Note: I do have another question about LineTraceSingle*() not working which could solve this problem by not having to use this function. I will try and link that question to this one.

Product Version: UE 4.12
Tags:
more ▼

asked Oct 17 '16 at 11:12 PM in C++ Programming

avatar image

NeonDrive
3 1 2 3

avatar image NeonDrive Oct 19 '16 at 12:08 PM

Im starting to think that my problem revolves around my world being null. as LineTraceSingle*() requires the same world variable. and as such i have not posted another question and believe that solving this issue will solve that one as well.

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

1 answer: sort voted first

A couple things could be going on here.

The last argument (5) is the line's thickness, in world units, so it may be that the line is being drawn but not thick enough for you to see (it may be thinner than a pixel) depending on the scale of your world.

You're also drawing a white line, which may be difficult to see based on the background it's being drawn against, you may want to try a different color.

Finally, you've defined the method within USwingShot, which I assume is an UObject. It may be that your GetWorld() call is returning NULL. You may want to verify GetWorld() is actually returning the proper context:

 void USwingShot::Draw(const FVector& Start, const FVector& End)
  {
      //TODO: Draw the line we want to check against
      UE_LOG(LogTemp, Warning, TEXT("Drawing Line"));
      UWorld* WorldContext = GetWorld();
      if (!WorldContext) {
         UE_LOG(LogTemp, Warning, TEXT("NO World Context Available!"));
         return;
 
      }
      // may be able to use the traceline function to also draw the line for this
      DrawDebugLine(
          GetWorld(),
          Start,
          End,
          FColor(255, 255, 255),
          true, // sets weather or not the line is in the world permanently
          -1.f, 0,
          5
      );    
  }

and if it's not, try passing the method a reference to your world from an actor, or from the level itself.

 void USwingShot::Draw(const FVector& Start, const FVector& End, UWorld* WorldContext)
  {
      //TODO: Draw the line we want to check against
      UE_LOG(LogTemp, Warning, TEXT("Drawing Line"));
      // may be able to use the traceline function to also draw the line for this
      DrawDebugLine(
          WorldContext,
          Start,
          End,
          FColor(255, 255, 255),
          true, // sets weather or not the line is in the world permanently
          -1.f, 0,
          5
      );    
  }
more ▼

answered Oct 18 '16 at 01:06 AM

avatar image

GigasightMedia
1.7k 43 12 61

avatar image NeonDrive Oct 18 '16 at 01:02 PM

Thanks for the response. Of what youve suggested the only thing i haven't tried is passing a refernce to the world from an actor. What ive managed to do for now is have it pass through the blueprint node. However I can't compile when i actually set it. Ill update if i solve the problem.

avatar image GigasightMedia Oct 18 '16 at 06:44 PM

Have you verified that GetWorld returns a NULL value?

 UWorld* WorldContext = GetWorld();
 if (!WorldContext) {
     UE_LOG(LogTemp, Warning, TEXT("NO World Context Available!"));
     return;
  
 }

That will at least narrow down your problem.

"What ive managed to do for now is have it pass through the blueprint node. However I can't compile when i actually set it."

Do you mean that you're attempting to pass a World value through the BP node?

What compile errors do you get?

What type of BP are you calling the method from (Actor, Object, etc)?

avatar image NeonDrive Oct 19 '16 at 12:06 PM

In all places in the c++ code GetWorld() is returning null.

How Ive attempted to input the World variable from the blueprint into the code: alt text If the highlighted variable is set i can't compile the blueprint.

I believe its an actor blueprint. Its the default 2Dsidescroller thing ()the one that by default is a blue man)

Thanks ND

avatar image GigasightMedia Oct 19 '16 at 04:48 PM

Your SwingShot looks like a UObject to me, not at actor, based on the name of the class: "USwingShot". The 'U' prefix indicates it's an object. When you call the the method from within the SwingShot Blueprint you're still within that class's context, so you can't set your World value from there. (If you had a valid world object it would work from GetWorld() in your c++ code). So you need to find an actor from outside your SwingShot Blueprint to give the SwingShot the it's world object; or have your level script give the SwingShot its world object.

Your Target value also looks weird. Is there a reason you are using a string reference to the class path rather than using "this" or setting the pin?

From what context are you calling this method? What BP are you in here?

avatar image NeonDrive Oct 19 '16 at 04:56 PM

I could easily believe that it is an object not a class based on what youve told me and what ive managed to find out over the last few days.

Im not sure why the target value has done that, it just happened at some point and wont let me change it to self or set from a pin.

This method is getting called from within the 2DSideScrolelrcharacter blueprint class. and what im about to test is whether or not ive messed up and not added it as a c++ component. To that end, i am just about to test whether or not i can get a non-null world from creating a new c++ class and adding it as a component. I will return soon with an update on that.

avatar image NeonDrive Oct 19 '16 at 05:13 PM

Right so Ive solved the issue of not having a world and im certain that it was the actor not being added as a component. from the test ive just done (created a new c++ component that only checks if the new class has a world) alt text

thats the new blueprint node, notice the grappling hook blue connection which i was previously unable to do. and also that grapplinghook is now in the component section which swingshot was not.

thanks for the help! How do i +rep you and mark as solved?

edit: i think ive done it :)

avatar image GigasightMedia Oct 19 '16 at 05:46 PM

Happy to help.

Good luck going forward.

(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