How to create a function using c++ in blueprint projects?

I am trying to call a function I created in a new c++ class, but it seems that the function can’t be seen. The type of the new c++ class is blueprint function library. And here is the code:

//PortalFunctionLibrary.h
#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Engine/TextureRenderTarget2D.h"
#include "PortalFunctionLibrary.generated.h"

/**
 * 
 */
UCLASS()
class DEMO_API UPortalFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
public:
	UFUNCTION(BlueprintCallable, Category = "PortalFunctionLibrary")
	static void ResizeRenderTarget(UTextureRenderTarget2D* render_target, float size_x, float size_y);
};
//PortalFunctionLibrary.cpp
#include "PortalFunctionLibrary.h"
void UPortalFunctionLibrary::ResizeRenderTarget(UTextureRenderTarget2D* render_target, float size_x, float size_y)
{
	if (render_target == nullptr)
		return;

	render_target->ResizeTarget(size_x, size_y);
}

After coding, I use “DebugGame Editor” to launch the UE 5 editor and try to call function “ResizeRenderTarget” by adding node in event graph. But it can’t be found.
Also, after I creat a new c++ class(blueprint function library), the .cpp and .h files will be opened in a new solution with nothing. I have to open the .sln file in my project folder to write the codes above. I wonder if they’re related.

Nothing immediately jumps out at me as wrong with the code itself.
It sounds like this is an issue that can be resolved by rebuilding from source.

Make sure unreal is closed throughout this

To do this, go to your project folder and delete Binaries, Saved, and the .sln file.

Then right click the .uproject and generate visual studio files.
image

After that, open the .sln and build as you would normally. After it finishes building, you’re safe to open the editor back up.

Hi there @Wh1teWax, hope you’re well!

This topic has been moved from International to Programming & Scripting: C++.

When posting, please review the categories to ensure your topic is posted in the most relevant space.

Thanks and happy developing! :slight_smile:

I’m sure there is a good chance you’ve already tried.

If UE5 still has the “Context Sensitive” checkbox when you right click on the blueprint graph, try unchecking then search for your function.

I haven’t had the chance to try UE5 yet. Your code does look fine at first glance though.