How get custom blueprint as parametr in C++ function

Hi, i have a custom class Cue_BP which has individual variables. I need to take the class of this Blueprint as a parameter to the function in C++ code. How to do it?

Hopefully someone comes by with the real answer, but I did it by setting things up such that any BP I need to reference has a C++ class as a parent. So in your case, Cue_BP would have a C++ parent class, and the function would take the parent class as a parameter.

Here’s some example code from my attempt. I was attempting to change the sun position in the default skybox, and it changed in the inspector but not in the game. So it works but apparently that’s not how you change the position of the sun in UE4 (I’m new to UE and transferred from Unity)

Now I’m hoping you already know how to do pointers, because I’m not going to explain that. But I will explain a few things about the code.
PtrToSky points to the Actor that has the skybox blueprint, not to the blueprint itself. I set it in the inspector for ease.
The blueprint is stored in MyBpClass and is a UClass object, which you get from obtaining the UClass from the Actor’s function, “GetClass”
Do NOT GetClass in the constructor. If there’s a segfault, the Unreal engine will crash as soon as it opens.
So basically I store a pointer to the function in the BeginPlay and just set it in the update. To get said pointer, you have to iterate through every variable in the Blueprint class and and store the right one. They’re stored as generic values and you have to attempt to cast them to UFloat or UInt or whatever.

It’s extremely tedious and took me a full day to get working and wrap my head around.

Just to be clear though, there are two functions in the skybox Blueprint and neither one of them actually changes the render according to the variable SunPosition.


void ASkyboxLight::BeginPlay()
{
	Super::BeginPlay();

	if (PtrToSky != nullptr)
	{
		MyBpClass = PtrToSky->GetClass();

		

		if (MyBpClass == nullptr)
		{
			UE_LOG(LogTemp, Warning, TEXT("Failure loading sky sphere blueprints!"));
		}
		else
		{
			UE_LOG(LogTemp, Log, TEXT("Success loading sky sphere blueprints!"));
			FName MyProperty(TEXT("Sun Height"));
			for (UProperty* Property = MyBpClass->PropertyLink; Property; Property = Property->PropertyLinkNext)
			{
				UFloatProperty* FloatProperty = Cast<UFloatProperty>(Property);
				if (FloatProperty && Property->GetFName() == MyProperty)
				{
					// Need more work for arrays
					//float MyFloatValue = FloatProperty->GetPropertyValue(Property->ContainerPtrToValuePtr<float>(PtrToSky));
					skyHeight = Property;
					//UE_LOG(LogTemp, Log, TEXT("Value is = %i"), MyFloatValue);
					break;
				}

				

				//Somehow we can't set this in the inspector so we're going it via scrpit
				refreshVarPtr = Cast<UBoolProperty>(Property);
				if (refreshVarPtr && Property->GetFName() == "Refresh Material")
				{
					refreshVarPtr->SetPropertyValue_InContainer(PtrToSky, true);
				}
			}
		}

		
	}
}

...
void ASkyboxLight::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	//PtrToLight->AddActorWorldOffset(FVector::UpVector * 10000.0F * DeltaTime);

	
	timeLeftToChange += DeltaTime;
	if (timeLeftToChange > TIMER)
	{
		timeLeftToChange -= TIMER;
		UFloatProperty* FloatProperty = Cast<UFloatProperty>(skyHeight);
		//float MyFloatValue = FloatProperty->GetPropertyValue(skyHeight->ContainerPtrToValuePtr<float>(PtrToSky));
		float MyFloatValue = 0.0F;
		colorID++;
		UE_LOG(LogTemp, Log, TEXT("Color ID: %i"), colorID);
		if (colorID == 1)
		{
			MyFloatValue = -0.5F;
		}
		if (colorID == 2)
		{
			MyFloatValue = 0.0F;
		}
		if (colorID == 3)
		{
			MyFloatValue = 0.5F;
		}
		if (colorID == 4)
		{
			MyFloatValue = 1.0F;
		}
		if (colorID == 5)
		{
			MyFloatValue = 0.5F;
		}
		if (colorID == 6)
		{
			MyFloatValue = 0.0F;
		}
		if (colorID == 7)
		{
			MyFloatValue = -0.5F;
		}
		if (colorID == 8)
		{
			MyFloatValue = -1.0F;
			colorID = 0;
		}
		//refreshVarPtr->SetPropertyValue_InContainer(PtrToSky, false);
		FloatProperty->SetPropertyValue_InContainer(PtrToSky, MyFloatValue);
		//refreshVarPtr->SetPropertyValue_InContainer(PtrToSky, true);

		FOutputDeviceDebug debug;
		PtrToSky->CallFunctionByNameWithArguments(*command, debug, this, true);
		
	}
	
}