Hey!
error C2248: ‘FSubobjectPtr::Object’ : cannot access protected member declared in class ‘FSubobjectPtr’
I have a struct and class that depend on each other like so:
UShipComponent.h:
// ~~~~~ Class Definitions ~~~~~ //
UCLASS()
class SPACEGAME_API UShipComponent : public UPrimitiveComponent
{
// Base Class for ShipComponent
GENERATED_UCLASS_BODY()
public:
AShip *ParentShip;
ResourceType INPUT_RESOURCE;
ResourceType OUTPUT_RESOURCE;
// How much resource should we try and get each Operate()?
float RESOURCE_REQUIRED;
// For replication we can only use arrays here (no dictionarys!)
UPROPERTY(Category = Components, EditAnywhere)
FShipComponentStruct InputComponents;
UPROPERTY(Category = Components, EditAnywhere)
FShipComponentStruct OutputComponents;
// Operate this component
virtual void Operate();
// Pull resources from this component
virtual float PullResource(ResourceType res, float requested_amount);
};
FShipComponentStruct.h:
// ~~~~~ Forward Declarations ~~~~~ //
class UShipComponent;
// ~~~~~ Struct Definitions ~~~~~ //
USTRUCT()
struct FShipComponentStruct
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
TArray< TSubobjectPtr<class UShipComponent> > Items;
FShipComponentStruct()
{
}
};
I also have a ship, and an engine:
AShip.h:
UCLASS()
class SPACEGAME_API AShip : public AActor
{
GENERATED_UCLASS_BODY()
public:
void Tick(float deltatime) override;
UPROPERTY(Category = Mesh, VisibleAnywhere)
TSubobjectPtr<class UStaticMeshComponent> HullComponent;
// A Global collection of every component on the ship
UPROPERTY()
FShipComponentStruct Components;
};
LightCruiser.h:
UCLASS()
class SPACEGAME_API ALightCruiser : public AShip
{
GENERATED_UCLASS_BODY()
public:
void Tick(float deltatime) override;
UPROPERTY(Category = Components, VisibleAnywhere)
TSubobjectPtr<UShipEngine> left_engine;
UPROPERTY(Category = Components, VisibleAnywhere)
TSubobjectPtr<UShipEngine> right_engine;
//UPROPERTY(Category = Components, VisibleAnywhere)
//TSubobjectPtr<UChemicalFuelTank> fuel_tank;
};
UShipEngine.h:
UCLASS()
class SPACEGAME_API UShipEngine : public UShipComponent
{
GENERATED_UCLASS_BODY()
public:
float ThrustStrength;
FVector GetThrustVector();
void Operate() override;
};
So, after i initalize the left and right engines in the lightcruiser implimentation (which works correctly till this point).
I then try to add them to the Components list:
ALightCruiser.cpp:
ALightCruiser::ALightCruiser(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// Cheap initialization:
left_engine = PCIP.CreateDefaultSubobject<UShipEngine>(this, TEXT("left_engine"));
left_engine->ThrustStrength = 10000;
left_engine->AttachParent = RootComponent;
right_engine = PCIP.CreateDefaultSubobject<UShipEngine>(this, TEXT("right_engine"));
right_engine->ThrustStrength = 10000;
right_engine->AttachParent = RootComponent;
////fuel_tank = PCIP.CreateDefaultSubobject<UChemicalFuelTank>(this, TEXT("fuel_tank"));
////fuel_tank->AttachParent = RootComponent;
////right_engine->InputComponents.Add(fuel_tank);
/// PROBLEMS ???
Components.Items.Add(left_engine);
Components.Items.Add(right_engine);
//Components.Add(fuel_tank);
UE_LOG(LogTemp, Warning, TEXT("Initialized lightcruiser object"));
}
Then it explodes and gives me the error, it sounds like something in the backend thats causing it to parse every field, and obviously because the array is of type UShipComponent and not UShipEngine, its trying to do something with an exclusively UShipEngine property (eg ThrustStrength)
Could anyone point me in the right direction?
Thanks