I am new to the Unreal engine and I am trying to add a custom actor to a plugin. So far I have managed to create the plugin and the actor independently. However when I move the actor code inside my plugin, the actor doesn’t behave as expected. For example the BeginPlay method doesn’t get called.
Looking at the code should give you a better idea of what I am doing and hopefully you can spot my mistake.
MyActor.h:
#pragma once
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class MYPROJECT_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
};
MyActor.cpp:
#include "MyProject.h"
#include "MyActor.h"
// Sets default values
AMyActor::AMyActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
UE_LOG(LogTemp, Warning, TEXT("I am AMyActor"));
}
// Called every frame
void AMyActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
As you can see, the actor simply prints out a message when BeginPlay is called. When the above code is located inside my project, I can create the actor in the editor and when I hit play I see the message in the log.
When I then move the code inside my plugin (I had to adjust a few includes), I can still create the actor in the editor but when I hit play I can’t see any message in the log.
I am probably doing something silly but I can’t work out why BeginPlay gets called in one case and not the other. I have been using the Paper2D plugin as an example and I noticed that APaperSpriteActor is pretty much empty and the implementation was moved inside a component. Maybe it is how I am supposed to do it.
Can anyone see what I am doing wrong?