Native Blueprint Code generations create wrong includes

Hello guys, hope this will be helpful :slight_smile:

Bug description

In my project i tried for the first time the blueprint nativization procedure, and it failed strangely. Digging it, i found out that it was generating the wrong includes for the blueprints.

In fact, it was skipping a parent include for some classes, for example if i had:

  1. C++ class named A
  2. BlueprintClass named B, derived from A
  3. BlueprintClass named C, derived from B

int the C class header it was correctly extending B, but it was including A directly, resulting in a compiling failure (unknown class B).

I had an hard time reproducing it on a fresh project, below you can find the steps.

It’s kinda hard to reproduce it, but this way it fails most of the times.

How to reproduce

Note: Since testing it requires packaging, i suggest to disable “Full rebuild”: i tested with it too, the result is the same.

Note 2: This steps list will show a setup for a working project, then will show how to mess it up, and how to workaround it.

Tested on 4.15.1-0


Initial setup to a working project:

  • Create a new “C++ Basic Code” project, name it “NativeTesting”: Desktop, maximum quality and no starter content
  • Build the newly created project in VS
  • Open the editor
  • Create a new C++ class, based on StaticMeshActor, and call it “MyStaticMeshActor”.
  • The following code will be generated, we’ll leave it as it is:

MyStaticMeshActor.h

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

#pragma once

#include "Engine/StaticMeshActor.h"
#include "MyStaticMeshActor.generated.h"

/**
 * 
 */
UCLASS()
class NATIVETEST_API AMyStaticMeshActor : public AStaticMeshActor
{
	GENERATED_BODY()
	
};

MyStaticMeshActor.cpp

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

#include "NativeTest.h"
#include "MyStaticMeshActor.h"
  • Close the editor and recompile
  • Now return to editor, and create a new blueprint class, with “MyStaticMeshActor” as parent, and call it “MyBase”. Open it, save, close.
  • Create a new blueprint class, with “MyBase” as parent, and call it “SecondBP”. Open it.
  • Add a cube component, save and close.
  • Put it in the level, and save it with name “MyLevel”
  • Open Project Settings, and go to Packaging section
  • Set BuildConfiguration to Development, uncheck “Full Rebuild”, and under blueprints set Nativization Method to “Inclusive”
  • Package the project for windows 64: it will work successfully.

Create the problem:

  • Open Project Settings, and go to Packaging section

  • Under blueprints set Nativization Method to “Exclusive”

  • Open “SecondBP”, go to class settings and enable “Nativize”

  • Try to package again.

  • it should fail with errors like these:

    UATHelper: Packaging (Windows (64-bit)): UnrealBuildTool: U:\Unreal Projects\NativeTesting\Intermediate\WindowsNoEditor\NativizedAssets\Source\NativizedAssets\Public\SecondBP__pf1010915279.h(8): error C2504: ‘AMyBase_C__pf1010915279’: base class undefined
    UATHelper: Packaging (Windows (64-bit)): UnrealBuildTool: U:\Unreal Projects\NativeTesting\Intermediate\WindowsNoEditor\NativizedAssets\Source\NativizedAssets\Public\SecondBP__pf1010915279.h(10): error C3646: ‘Super’: unknown override specifier

In fact, looking at the generated code, in Intermediate/WindowsNoEditor/NativizedAssets/Source/Public/SecondBP__****.h, we have:

#include "Blueprint/BlueprintSupport.h"
#include "NativeTesting/MyStaticMeshActor.h"
class UStaticMeshComponent;
#include "SecondBP__pf1010915279.generated.h"
UCLASS(config=Engine, Blueprintable, BlueprintType, meta=(ReplaceConverted="/Game/SecondBP.SecondBP_C", OverrideNativeName="SecondBP_C"))
class ASecondBP_C__pf1010915279 : public AMyBase_C__pf1010915279
{

[…]

Notice how it’s including MyStaticMeshActor.h instead of MyBase_C__pf1010915279.h


Workaround:

  • Open the blueprint “MyBase”
  • Connect something to “BeginPlay”, like a “Print String” node, save and close (this will make it a “normal blueprint”, not a data-only).
  • Try to package again, it will work.

Current Behaviour

On exclusive nativization, seems like it fails to generate the correct includes if the parent is a data-only blueprint.
In fact, in the SecondBP_****.h it places:

#include "NativeTesting/MyStaticMeshActor.h"

instead of:

#include "MyBase__pf1010915279.h"

As already stated, it seems directly related to data-only blueprint, but it doesn’t happen on an inclusive nativization.

Expected behaviour

It should always generate the correct include (with the right parent class).

Conclusions

I had an hard time tackling this, it seemed pretty randomic, and i lost a lot of time due to the numerous packaging launches.

I noticed that sometimes it still work, but trying around i can always make it fail in the same way (this is the simplest i found).

I hope this can help you, and maybe others that had issues like me, with the workaround.

Let me know if you need more infos :slight_smile:

Simone Daminato

[edit1] : fixed some typos.

Hey

Thank you for submitting a bug report. I have reproduced this issue and logged a report for it here Unreal Engine Issues and Bug Tracker (UE-44488) . You can track the report’s status as the issue is reviewed by our development staff. Please be aware that this issue may not be prioritized or fixed soon.

Cheers

It would be best to create a new post to track each issue separately.

Thanks a lot .
I found another small issue of nativization with Arrays of TSubclassOf.
Do you prefer if i report it in here or open another thread?