How to convert a blueprint to a C++ file ?

Hallo
I created a blueprint using the unreal visual blocks and now I am looking for any methods to convert it into c++ file so that I can use it for my another project. Is it possible ? if so, any suggestions will be helpful.

There is no automation tool for this process. You need to look into unreal documentation to find the equivalent c++ functions to nodes.

If you double click a bp node it will open up c++ and sometimes you might see what is going on in the cpp implementation, but many native nodes are for instance parts of various kismet libraries (e.g. UKismetMathLibrary) with extra operations.

So when we double click, does we get a generation c++ code or what we implemented in the blueprint( like if we have an input, does the c++ file also have that ?)

And is it possible to convert the blueprint entirely to c++ by using these functions ?

It should automatically load your coding IDE and go to the function if it exposed

This will be your go to page though

If you search for a function in c++ you will most likely get a sub page of the documentation.

To use a class you need to add it’s relevant #include header file and if it uses a module not present in your project then you need to add it your project build file under

PublicDependencyModuleNames.AddRange(new string[] {  /* inside the brackets go the needed modules  */ }); 

I think i am little confused…Actually what i meant is that can i able to combine the c++ coes of different blueprint nodes to get a complete c++ file for my blueprint ?

For example: Below is my blueprint to make a procedural mesh…so is it possible to combine the c++ codes of each node to get a complete c++ file ?

Is triangle test a custom function or from a plugin?

It is a custom function which gives the vertex values

All of this can be easily rewritten into a single c++ node but you need to also convert the triangle test function.

You mean I need to write the codes or can i use the code snipet which opens when i double click on the blueprint node ?

You need to write it all by hand

so basically there is no method available to convert the whole blueprint into c++ ? I have to create my own to get the same blueprint, right ?

1 Like

yes

any may be you caan comment on my requirement. I alreay created my own blueprint in unreal and my .uasset file is ready.

Now i am planning to use my bleprint on CARLA (which is a simulator build on unreal). I am planning to place my blueprint alongside with carla files so that when i build the carla, i can able to see my blueprints in the contents folder along with build-in contents. Is there any way ?

Show me the inside of triangle test and I’ll see if I can make it.

Here is the function traingle test. Also there is a small math function also in it. I am attaching that also…


PS: Triangle function is basically used to find the corddinates for the procedural mesh !

is the tand and equivalent of

  • Does a boolean AND of the ::Value static members of each type, but short-circuits if any Type::Value == false.

or is it a tangent function that returns it’s value in degrees?
(Guessing it’s the tangent due to the variables not being split by a delimiter)

it is a tangent function in degree >> gives the value of tangent in degree

Header .h

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Templates/Tuple.h" 
#include "ProceduralLibrary.generated.h"


USTRUCT(BlueprintType)
struct FTupleFloat
{
	GENERATED_BODY();
public:
	UPROPERTY(BlueprintReadOnly)
		float HFOV;

	UPROPERTY(BlueprintReadOnly)
		float VFOV;

	UPROPERTY(BlueprintReadOnly)
		float Range;
};

/**
 * 
 */
UCLASS()
class YOUR_API UProceduralLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

		UFUNCTION(BlueprintCallable)
		static void ProceduralMesh(AActor* PassedParent, FRotator Rotation, FVector Translation, float HAOV, float VAOV, float Range, int32 Negation);

	UFUNCTION(BlueprintCallable)
		static TArray<FVector> TriangleTest(float HAOV, float VAOV, float Range, int32 Negation);

	UFUNCTION(BlueprintCallable)
	static FTupleFloat FOVPara(float HAOV, float VAOV, float Range);
};

.cpp

#include "ProceduralLibrary.h"
#include "Engine/World.h"
#include "ProceduralMeshComponent.h" 


void UProceduralLibrary::ProceduralMesh(AActor* PassedParent, FRotator Rotation, FVector Translation, float HAOV, float VAOV, float Range, int32 Negation) {
	if (PassedParent != nullptr) {
		UWorld* world = PassedParent->GetWorld();
		UProceduralMeshComponent* procdMesh = NewObject<UProceduralMeshComponent>(PassedParent);
		procdMesh->RegisterComponent();
		TArray<FVector> vertices = TriangleTest(HAOV, VAOV, Range, Negation);

		FJsonSerializableArrayInt Triangles = { 0,1,2,0,3,2,0,4,3,0,4,1 };
		TArray<FVector2D> UV0 = {
			FVector2D(0,0),
			FVector2D(0,1),
			FVector2D(1,0),
			FVector2D(0,0),
			FVector2D(0,0),
			FVector2D(0,0),
			FVector2D(0,0),
			FVector2D(0,0),
			FVector2D(0,0),
			FVector2D(0,0),
			FVector2D(0,0),
			FVector2D(0,0)
		};

		TArray<FColor> Color;
		TArray<FVector> normals;
		TArray<FProcMeshTangent> tangents;

		procdMesh->CreateMeshSection(0, vertices, Triangles, normals, UV0, Color, tangents, false);
	}
}


TArray<FVector> UProceduralLibrary::TriangleTest(float HAOV, float VAOV, float Range, int32 Negation) 
{
	TArray<FVector> triangles;
	FTupleFloat fovPara = FOVPara(HAOV, VAOV, Range);

	float HalfHFOV = (fovPara.HFOV / 2.0f);
	float HalfVFOV = (fovPara.VFOV / 2.0f);
	
	FVector firstOP = FVector::Zero();
	triangles.Add(firstOP);

	float firstSum = firstOP.X + fovPara.Range;
	float secondSum = firstOP.Y + HalfHFOV;
	float thirdSum = firstOP.Z + HalfVFOV;

	FVector secondOp;
	secondOp.X = firstSum;
	secondOp.Y = secondSum;
	secondOp.Z = thirdSum;
	triangles.Add(secondOp);

	FVector thirdOp;
	thirdOp.X = firstSum;
	thirdOp.Y = secondSum;
	thirdOp.Z = thirdSum;
	triangles.Add(thirdOp);

	FVector fourthOP;
	fourthOP.X = firstOP.Y + fovPara.Range;
	fourthOP.Y = firstOP.Y - HalfHFOV;
	fourthOP.Z = Negation * thirdSum;
	triangles.Add(fourthOP);

	FVector fifthOP;
	fifthOP.X = firstSum;
	fifthOP.Y = firstSum;
	fifthOP.Z = Negation * thirdSum;
	triangles.Add(fifthOP);
	
	return triangles;
}

FTupleFloat UProceduralLibrary::FOVPara(float HAOV, float VAOV, float Range) {
	
	float HFOV = (2 * (FMath::RadiansToDegrees(FMath::Tan(HAOV / 2.0f)))) * Range;
	float VFOV = (2 * (FMath::RadiansToDegrees(FMath::Tan(VAOV / 2.0f)))) * Range;
	
	FTupleFloat ret;
	ret.HFOV = HFOV;
	ret.VFOV = VFOV;
	ret.Range = Range;
				
	return ret;
}

Hope I didn’t mess up and of the links in the test triangle. They were a bit hard to read. Best double check if the connections are the same.

Make sure you build file has the extra module ProceduralMeshComponent

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay",  "ProceduralMeshComponent"});

Thanks for the help…I really appreciate it…

You mean i need to add in the cmake file ?

Your project should have a file in it your game directory source/projectname/projectname.Build.cs inside you have the modules like I described.

Oh and in the files I showed you, you need to replace YOUR_API with your project api (usually uppercase project name followed by _API)