Download

Converting Blueprints to C++ code

Hello,

I am new to UE, not new to programming, I graduate from a Software Engineering degree in a few weeks. I was wondering if there was any good resource I can use to make the process of converting blueprints to C++ any easier? i.e this type of node is this way, this other type of node you code this way, etc

Any guidance would be greatly received!

What I found for myself is that manual converting is much easier than using the “File → Developer → Convert to C++” Function in the Blueprint Window.
That generated code is very unreadable bloated with extra state stuff…

So in my oppinion it depends on what you want to achieve…

  • If you want to use Blueprints but have better performance → Use Blueprint Nativization while cooking

  • If you are just curious how it would look like… → Forget about it… as it is not worth the work in my oppinion

  • If you want to refactor something from Blueprints to C++ → Do it manually (most of the stuff is exactly named like in the Blueprints)

  • only Datatypes have some additional Prefixes like A (Actor), U (Object or Component), F (Struct or Enum)

  • and sometimes for some methods you need to know where it comes from originally. Because Blueprints hide that sometimes like UGameplayStatics::GetAllActorsOfClass in C++ where in Blueprint you just need to type GetAllActorsOfClass

But if you want to get back to point 2…
Just Create two new Unreal Projects.

  • one with the ThirdPerson Character Blueprint Template
  • the other one with the ThirdPerson Character C++ Template

Then compare :slight_smile:

Starter Resources:
https://forums.unrealengine.com/development-discussion/c-gameplay-programming/8694-getting-started-c-gameplay-programming-references

Easy (uncomplete) Example:

C++:



void ALightSwitchCodeOnly::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
    if (OtherActor && (OtherActor != this) && OtherComp)
    {
         PointLight1->ToggleVisibility();
    }
}

void ALightSwitchCodeOnly::OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
    if (OtherActor && (OtherActor != this) && OtherComp)
    {
        PointLight1->ToggleVisibility();
    }
}


**Blueprint:

https://docs.unrealengine.com/portals/0/images/Gameplay/ClassCreation/BlueprintOnly/BP_Only_EventGraph.png
**

I cannot see that “File->Developer->Convert to C++” option, where can i find it?

1- Do you really have to do so much defensive programming with if otherActor, otherComp, etc… I fail to see how you could collide with something that is not an actor and/or that has no primitive component.

2- Don’t do too much blueprint to C++ refactoring, it will have the side effect of making you realize how short a complex blueprint graph can be in C++ :wink:

I don’t see this option either. I didn’t start a C++ project. I started a Blueprint project. Is it possible to convert my blueprints to C++ now and how?

You have to open a blueprint first and you will see the menu.