C++ Blueprint Function not showing up in Blueprint Editor

Hi all,

I am trying to get a C++ function to show up in the Blueprint editor. I create a new C++ class > Copy the code into the .h and .cpp files and change the names to be the name of my game > Build the solution > Open the editor and the function is not there. I tried these exact steps on another project and it worked. So is there something I could have accidental changed that is making this not work for one of my projects? My Engine version is 4.9.2 and I am using Perforce Source Control. Below is the code I am using.


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

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "HUDBlueprintLibrary.generated.h"

class MOSEXAMPLE_API UHUDBlueprintLibrary : public UBlueprintFunctionLibrary
	* Converts a world location to screen position for HUD drawing. This differs from the results of FSceneView::WorldToScreen in that it returns a position along the edge of the screen for offscreen locations
	* @param		InLocation	- The world space location to be converted to screen space
	* @param		EdgePercent - How close to the edge of the screen, 1.0 = at edge, 0.0 = at center of screen. .9 or .95 is usually desirable
	* @outparam	OutScreenPosition - the screen coordinates for HUD drawing
	* @outparam	OutRotationAngleDegrees - The angle to rotate a hud element if you want it pointing toward the offscreen indicator, 0° if onscreen
	* @outparam	bIsOnScreen - True if the specified location is in the camera view (may be obstructed)
	UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext), Category = "HUD|Util")
		static void FindScreenEdgeLocationForWorldLocation(UObject* WorldContextObject, const FVector& InLocation, const float EdgePercent, FVector2D& OutScreenPosition, float& OutRotationAngleDegrees, bool &bIsOnScreen);



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

#include "MOSExample.h"
#include "HUDBlueprintLibrary.h"

void UHUDBlueprintLibrary::FindScreenEdgeLocationForWorldLocation(UObject* WorldContextObject, const FVector& InLocation, const float EdgePercent, FVector2D& OutScreenPosition, float& OutRotationAngleDegrees, bool &bIsOnScreen)
	bIsOnScreen = false;
	OutRotationAngleDegrees = 0.f;	

	if (!GEngine) return;

	const FVector2D ViewportSize = FVector2D(GEngine->GameViewport->Viewport->GetSizeXY());
	const FVector2D  ViewportCenter = FVector2D(ViewportSize.X / 2, ViewportSize.Y / 2);

	UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);

	if (!World) return;

	APlayerController* PlayerController = (WorldContextObject ? UGameplayStatics::GetPlayerController(WorldContextObject, 0) : NULL);

	if (!PlayerController) return;

	ACharacter* PlayerCharacter = Cast<ACharacter>(PlayerController->GetPawn());

	if (!PlayerCharacter) return;

	FVector Forward = PlayerCharacter->GetActorForwardVector();
	FVector Offset = (InLocation - PlayerCharacter->GetActorLocation()).GetSafeNormal();

	float DotProduct = FVector::DotProduct(Forward, Offset);
	bool bLocationIsBehindCamera = (DotProduct < 0);

	if (bLocationIsBehindCamera)
		// For behind the camera situation, we cheat a little to put the
		// marker at the bottom of the screen so that it moves smoothly
		// as you turn around. Could stand some refinement, but results
		// are decent enough for most purposes.

		FVector DiffVector = InLocation - PlayerCharacter->GetActorLocation();
		FVector Inverted = DiffVector * -1.f;
		FVector NewInLocation = PlayerCharacter->GetActorLocation() * Inverted;

		NewInLocation.Z -= 5000;

		PlayerController->ProjectWorldLocationToScreen(NewInLocation, OutScreenPosition);
		OutScreenPosition.Y = (EdgePercent * ViewportCenter.X) * 2.f;
		OutScreenPosition.X = -ViewportCenter.X - OutScreenPosition.X;

	PlayerController->ProjectWorldLocationToScreen(InLocation, OutScreenPosition);//*ScreenPosition);

	// Check to see if it's on screen. If it is, ProjectWorldLocationToScreen is all we need, return it.	
	if (OutScreenPosition.X >= 0.f && OutScreenPosition.X <= ViewportSize.X
		&& OutScreenPosition.Y >= 0.f && OutScreenPosition.Y <= ViewportSize.Y)
		bIsOnScreen = true;

	OutScreenPosition -= ViewportCenter;

	float AngleRadians = FMath::Atan2(OutScreenPosition.Y, OutScreenPosition.X);
	AngleRadians -= FMath::DegreesToRadians(90.f);

	OutRotationAngleDegrees = FMath::RadiansToDegrees(AngleRadians) + 180.f;

	float Cos = cosf(AngleRadians);
	float Sin = -sinf(AngleRadians);

	OutScreenPosition = FVector2D(ViewportCenter.X + (Sin * 180.f), ViewportCenter.Y + Cos * 180.f);

	float m = Cos / Sin;

	FVector2D ScreenBounds = ViewportCenter * EdgePercent;

	if (Cos > 0)
		OutScreenPosition = FVector2D(ScreenBounds.Y / m, ScreenBounds.Y);
		OutScreenPosition = FVector2D(-ScreenBounds.Y / m, -ScreenBounds.Y);

	if (OutScreenPosition.X > ScreenBounds.X)
		OutScreenPosition = FVector2D(ScreenBounds.X, ScreenBounds.X*m);
	else if (OutScreenPosition.X < -ScreenBounds.X)
		OutScreenPosition = FVector2D(-ScreenBounds.X, -ScreenBounds.X*m);
	OutScreenPosition += ViewportCenter;	


This code is from the kind people jeff_lamarche and ZioYuri78 over at this forum post

Maybe try removing the meta stuff related to world context? Do you have any other C++ functions that appear in blueprints correctly? Honestly this should be posted in the C++ area, as most of us blueprinters don’t know anything about C++.

This is the only C++ function. I’ll post it in the C++ area thank you.

I don’t see anything wrong with it. It should be in HUD > Util, in the blueprint context menu. Does it appear when you click into the C++ Classes folder in the content browser of your project?

I can’t find it in the content browser. I go into View Options and check all the boxes then search for it and it is not there.

Try moving the meta to the end of the macro. I have no idea why that doesn’t work though. at first glance it seems fine. odd.

I just tried the code and it worked fine for me - nothing changed except the project name. How are you adding it, File>New C++ Class… in the editor?
When this has happened to me before, it was just problems with Hot Reload, closing the editor, and rebuilding the solution in Visual Studio fixed it, though I presume you’ve done that a few times by now.

You are talking about this line correct: UFUNCTION(BlueprintPure, meta = (WorldContext = “WorldContextObject”, CallableWithoutWorldContext), Category = “HUD|Util”)

I just tried to make it like: UFUNCTION(BlueprintPure, Category = “HUD|Util”) and like: UFUNCTION(BlueprintPure, Category = “HUD|Util”, meta = (WorldContext = “WorldContextObject”, CallableWithoutWorldContext))

Neither worked :frowning:

And yes I add a new file from the editor by going File > new C++ class > Copy the code into the .h and .cpp files and change the names to be the name of my game > Build the solution. I have tried rebuilding the game from the Solution Explorer and that didn’t work.

Would it be good to delete all the visual studio files then right click the project file and re generate the visual studio files? Or would that just break it more?

You could try deleting the binaries and intermediate folder yes. Then regenerate, and do a Full rebuild in Visual Studio.

I deleted the Binaries and Intermediate folders > right clicked the .uproject and generated visual studio project files > right click the game in the Solution Explorer and rebuilt > right click the engine in the Solution Explorer and rebuilt.

Still didn’t work. The function does not show up and I cannot find the classes in the Content Browser.

I migrated all the content into a new empty project and created a new c++ class and it is working now. Don’t know why it won’t work in my other project. Could it be because the project was connected to source control?

I have a project on my end that is connected to source control, and I can add C++ functions just fine :\ Maybe try connecting Visual Studio itself to source control?

Thanks for all the help guys. I ended up migrating all my content to a new project and the C++ class worked in that. I then made a new source control project.

4.16 still has this issue, please note and hope it will be fixed

4.16,too.After reopen anything it’s still not showing.

Currently the same issue in UE4.19. The C++ BlueprintLibrary class does show up when creating a new asset from the editor, but the functions won’t display in a blueprint graph. My Library is part of a plugin. Weired thing is: There are other plugins in the same project that do it the same way and show up correctly.

I had to restart the Engine, then it showed up…

For anyone having this, I found that “Context Sensitive” unchecked got what I needed. It looks like it couldnt figure out that I was casting to a different object which had the function I was looking for. This box is in the right click menu above the search bar (4.22)

In 4.26 it’s not showing up too neither restarting the editor nor starting a new project, I also tried disabling the “context sensitive” checkbox but that didn’t work too