[Plugin] Why does my plugin forces me to include headers when outside of the plugin it didn't

Hi there,

Here is a code snippet I transferred from non-plugin into a plugin.
Before it was a plugin, I never had to add include headers.
Now it is not only required for me to be able to package the plugin, but it asks it in the header.

I find it odd that I would have to include headers when I have their Modules as public dependencies in the plugin’s .Build.cs file.

Am I missing something?

#pragma once

#include "Components/ActorComponent.h"
#include "GameFramework/Actor.h"
#include "Engine/World.h"

#include "SinOscillation.generated.h"

UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class LUDWELLUNREALMATH_API USinOscillation : public UActorComponent
{
	GENERATED_BODY()

public:
	USinOscillation();

protected:
	virtual void BeginPlay() override;

public:
	virtual void TickComponent(float DeltaTime, ELevelTick TickType,
	                           FActorComponentTickFunction* ThisTickFunction) override;

	UFUNCTION(Category = "Ludwell|Math", BlueprintCallable)
	void Oscillate() const;

private:
	FVector InitialLocation;

	UPROPERTY(Category = "Values", EditAnywhere)
	FVector Amplitudes = FVector(1.0f, 1.0f, 1.0f);

	UPROPERTY(Category = "Values", EditAnywhere)
	FVector Frequencies = FVector(1.0f, 1.0f, 1.0f);
};

// Oscillate from the source file
void USinOscillation::Oscillate() const
{
	const float Time = GetWorld()->GetTimeSeconds();

	const float NewX = Amplitudes.X * FMath::Sin(Time * Frequencies.X);
	const float NewY = Amplitudes.Y * FMath::Sin(Time * Frequencies.Y);
	const float NewZ = Amplitudes.Z * FMath::Sin(Time * Frequencies.Z);

	const FVector NewLocation = InitialLocation + FVector(NewX, NewY, NewZ);
	GetOwner()->SetActorLocation(NewLocation);
}

This is caused by Unreal’s unity builds system.

I actually went over this exact problem in a recent thread on X: Alex :eagle: on X: “Unreal Engine is using Unity builds. I know this might sound confusing the first time you hear it but let me explain :point_down:t3::thread:” / X (twitter.com)

tldr; When this code was inside a “non-plugin”, it was probably bundled with other files. Unity builds bundles code files from the same module together to speed up compilation.

If you want to confirm this is the case, move your code back and rebuild with bUseUnity = false; inside your build.cs file.

1 Like