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.

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
     );    
 }

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.

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)?

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:

111539-swingshotworldinput.png

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

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.

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?

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.

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)

http://puu.sh/rOrBo/161be2852f.jpg

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 :slight_smile:

Happy to help.

Good luck going forward.