Identifier DrawLine is undefined

Hi,

Could you include the full error and also show the code snippet to give more context to the issue?

I’m currently getting the error that DrawLine() is undefined, which would normally just mean I forgot to include the header file where it’s defined. I looked up the include statement I needed in the documentation here and added the line: #include “Blueprint/WidgetBlueprintLibrary.h” to the top of my custom class header file. However, I still get the error that it’s undefined. I’ve also tried closing and re-opening Visual Studio/the engine and rebuilding the solution to see if that would fix it, but no such luck. Any ideas?

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Blueprint/WidgetBlueprintLibrary.h"

/**
 * 
 */
class SKETCHWITHDEPTH_API CPP_2D_Curve
{
protected:
	bool is_vertical;
	bool is_dirty;
	TArray<FVector2D> curve_points;
	FColor color;
	FVector4 bounding_box;

public:
	static const float ENDPOINT_SNAP_DISTANCE;

	CPP_2D_Curve();
	CPP_2D_Curve(const CPP_2D_Curve& c1);
	~CPP_2D_Curve();

	int add_curve_point(FVector2D p);
	TArray<FVector2D> get_curve_points();
	void clear_curve();
	void set_curve_color(FColor col);
	FVector2D get_start_point();
	FVector2D get_end_point();
	bool check_if_vertical();
	void draw_curve(FPaintContext &pc, FVector2D viewport_size);
};

I appear to need some practice with entering code snippets on this site… The above code is the header file for my custom class, the relevant part of the .cpp file is posted below:

#include "CPP_2D_Curve.h"

......

void CPP_2D_Curve::draw_curve(FPaintContext& pc, FVector2D viewport_size)
{
	for (int i = 1; i < curve_points.Num(); ++i)
	{
		DrawLine(); //Haven't put the parameters in yet, but this is the method I want to call
	}
}

The error I’m getting is the following (copied from the error list in visual studio):

Code: E0020
Description: identifier “DrawLine” is undefined

Thought I already commented on this but I can’t see the comment anymore, so if you see duplicate posts, my apologies. The error is the following:

Code: E0020
Description: identifier “DrawLine” is undefined

Header File:

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Blueprint/WidgetBlueprintLibrary.h" // This is the include statement referenced in OP

/**
 * 
 */
class SKETCHWITHDEPTH_API CPP_2D_Curve
{

...
public:
...
	void draw_curve(FPaintContext &pc, FVector2D viewport_size);
};

CPP File:

// Fill out your copyright notice in the Description page of Project Settings.


#include "CPP_2D_Curve.h"

...

void CPP_2D_Curve::draw_curve(FPaintContext& pc, FVector2D viewport_size)
{
	for (int i = 1; i < curve_points.Num(); ++i)
	{
		DrawLine(); // Haven't added the parameters here yet, but this is the call that results in the error
	}
}

So I’ve tried to use the reply button twice now, and every time I reload the page my reply seems to disappear, so I guess I’ll post this in an answer instead. Also, ellipses are used in place of irrelevant code for the sake of brevity.

Code: E0020
Description: identifier “DrawLine” is undefined

Header File:

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Blueprint/WidgetBlueprintLibrary.h" // This is the include statement referenced in OP

/**
 * 
 */
class SKETCHWITHDEPTH_API CPP_2D_Curve
{

...
public:
...
	void draw_curve(FPaintContext &pc, FVector2D viewport_size);
};

CPP File:

// Fill out your copyright notice in the Description page of Project Settings.


#include "CPP_2D_Curve.h"

...

void CPP_2D_Curve::draw_curve(FPaintContext& pc, FVector2D viewport_size)
{
	for (int i = 1; i < curve_points.Num(); ++i)
	{
		DrawLine(); // Haven't added the parameters here yet, but this is the call that results in the error
	}
}

Friend of mine offline figured this out for me; DrawLine is part of the UWidgetBlueprintLibrary namespace, so I needed to call UWidgetBlueprintLibrary::DrawLine() instead of just DrawLine().