Hi,
I am trying to create a simple plugin “BasicCollectibles” for my game with C++ in VS2022. Everything was working fine:
- Create the plugin
- Add an interface “CollectibleInterface”
- Add an implemtation class deriving from AActor “BasePickup”
- Create a BP within the content folder of my plugin (BP_BasePickup) which derives from BasePickup and therefore inherits the interface “CollectibleInterface”
Then I extended the BP_ThirdPersonCharacter from Unreals Template by a collision sphere and added this little logic:
I dropped a few instances of BP_BasePickup into the level and the output showed the number of pickups within the CollisionSphere.
So far so good, but when I changed the “Class Filter” to BP_BasePickup from my plugin it works fine until I close the editor.
After attempting to reopen the UE editor again it gives me this error:
„Error: CDO for class /BasicCollectibles/BP_BasePickup.BP_BasePickup_C did not load!“
This will occur until I delete the BP_BasePickup.uasset manually from the project.
I also tested the “Class Filter” with a BP_class within the project. It was working fine, no problems. So I am guessing I did sth. wrong with my plugin here.
What am I missing here? What am I doing wrong?
CollectibleInterface.h:
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "CollectibleInterface.generated.h"
UINTERFACE(MinimalAPI, Blueprintable)
class UCollectibleInterface : public UInterface
{
GENERATED_BODY()
};
class BASICCOLLECTIBLES_API ICollectibleInterface
{
GENERATED_BODY()
public:
void OnCollected(AActor* Collector);
};
CollectibleInterface.cpp:
#include "CollectibleInterface.h"
BasePickup.h:
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CollectibleInterface.h"
#include "BasePickup.generated.h"
UCLASS(Blueprintable)
class BASICCOLLECTIBLES_API ABasePickup : public AActor, public ICollectibleInterface
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ABasePickup();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void OnCollected_Implementation(AActor* Collector) override;
};
BasePickup.cpp:
#include "BasePickup.h"
/* Sets default values */
ABasePickup::ABasePickup()
{
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ABasePickup::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ABasePickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ABasePickup::OnCollected_Implementation(AActor* Collector)
{
if (Collector)
{
UE_LOG(LogTemp, Log, TEXT("Collected by: %s"), *Collector->GetName());
}
Destroy();
}