This is the first time I am creating a instance of a class using a TSubobjectPtr so I generally copied what the format that was present in the templates but it crashed the editor when I opened the project.
Here are the .h and .cpp files
.H
UCLASS()
class BARRELFALL_API AInventory : public AActor
{
GENERATED_UCLASS_BODY()
/** Currently equiped weapon */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
TSubclassOf<class ABaseProjectile> CurrentProjectile;
void FireProjectile(FVector, FRotator);
};
.cpp
#include "BarrelFall.h"
#include "BaseProjectile.h"
#include "Inventory.h"
AInventory::AInventory(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
CurrentProjectile = ABaseProjectile::StaticClass();
}
void AInventory::FireProjectile(FVector SpawnLocation, FRotator SpawnRotation)
{
GetWorld()->SpawnActor<ABaseProjectile>(CurrentProjectile, SpawnLocation, SpawnRotation);
}
In My character class I made a
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory)
TSubobjectPtr<class AInventory> CharacterInventory;
And I assigned I created an instance the way it was made in c++ templates
CharacterInventory = PCIP.CreateDefaultSubobject<AInventory>(this, TEXT("CharacterInventory"));
But when I open the project which has the TSubobjectPtr the editor crashes.