Confused about class header declarations for Unreal

Hi all I am going through some of the documentation and I realize that it’s a bit outdated as I have had to tweak things slightly in each example so far. I am looking at this one now and I am running into a similar issue as in some of the others, and I could use some clarification.

For example, this section of code/header file (found at Components and Collision | Unreal Engine Documentation)

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PawnMovementComponent.h"
#include "CollidingPawnMovementComponent.generated.h"

UCLASS()
class HOWTO_COMPONENTS_API UCollidingPawnMovementComponent : public UPawnMovementComponent
{
    GENERATED_BODY()

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

The above code throws errors with its associated .cpp file when building. But the code compiles successfully if I remove the HOWTO_COMPONENTS_API part just after the class keyword in the UCollidingPawnMovementComponent declaration.

What is this? It looks a bit foreign to me. And I seem to have the issue with each of the older UE4 examples. Thanks!

it’s because your project has a different name than HOWTO_COMPONENTS

just put your project name there instead like

MYPROJECT_API

1 Like

Either change it to the module name like ugmoe suggests or remove it (as you found).

That macro is part of the dll/module exporting functionality. The editor builds all the modules of a plugin (including your game module) as a dll (dynamic link library) so there has to be a little bit of extra info to specify what “things” should be accessible to those users of the dll.

If you’re not doing any plugin development or otherwise trying to organize your code across multiple plugins/modules then you can just omit this macro from any examples.

1 Like

Thank you both

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.