Converting Blueprints to C++ code

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
**

4 Likes