2

I am learning unreal engine and I know a little about C++. However, I am not entirely sure what is going on in this line of code. Can someone explain to me like i'm 5?

class ESCAPEROOM_API UWorldPosition : public UActorComponent

We are defining the function as UActorComponent which is understood, but not sure what is going on in this piece:

class ESCAPEROOM_API UWorldPosition

The rest of the code,

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "WorldPosition.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class ESCAPEROOM_API UWorldPosition : public UActorComponent <==========
{
    GENERATED_BODY()

public: 
    // Sets default values for this component's properties
    UWorldPosition();

protected:
    // Called when the game starts
    virtual void BeginPlay() override;

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

        
};


Snoopy
  • 1,257
  • 2
  • 19
  • 32
  • This is not a function definition. This is the definition of a class called `UWorldPosition` that is derived from a base class called `UActorComponent` – Ayushya Dec 20 '20 at 05:54
  • What is the name `ESCAPEROOM_API ` for? – Snoopy Dec 20 '20 at 06:02

2 Answers2

3

We are defining the function as UActorComponent

Not true, you are defining a class UWorldPosition which is publically derived from another class UActorComponent.

The ESCAPEROOM_API part is not standard C++ but it is likely to be a macro whose purpose is to export that class from a shared library. See here.

Since you are beginner at C++ you'd probably find learning about it easier with a good book. C++ is a complex language.

john
  • 85,011
  • 4
  • 57
  • 81
1

(Too long for a comment.)

Without knowing a thing about unreal engines, but having browsed C++ code before, this is what I see on a first quick read, which tells me that the code defines class UWorldPosition derived from UActorComponent with the purpose of overriding two virtual functions defined in the base.

class ... UWorldPosition : public UActorComponent
{
    ... BeginPlay() override;

    ... TickComponent(...) override;      
};

Those are the parts left after skipping over the all-uppercase macros (UCLASS, ESCAPEROOM_API) which must be some non-standard implementation details/attributes, boilerplate code (GENERATE_BODY, default constructor), and less interesting or redundant bits (#include, virtual).

dxiv
  • 16,984
  • 2
  • 27
  • 49