I know this problem has been mentioned previously, and I understand the need of having a default constructor with FObjectInitializer.
I read this
thread, but is still unclear to me how to proceed when I have an AActor included in another AActor, like the following
UCLASS()
class THIRDPERSON_API AMyActorX : public AActor
{
GENERATED_BODY()
public:
AMyActorX (const FObjectInitializer& ObjectInitializer);
AMyActorY Y;
};
I know I can’t add extra parameters to the default constructor, instead I tried using in the constructor FObjectInitializer for MyObjectY
AMyActorX ::AMyActorX (const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer), Y(ObjectInitializer)
{
}
Which compiles but will produce a crash on startup, my guess is that it producing some kind of cycling dependency of the objects when creating them, but please elaborate.
I can solve the problem by using a pointer for AMyActorY*, it will compile and run correctly.
But the question is, how would it be correctly implemented using AMyActorY instance?
Also, would there be a workaround if declaring this Actor as static?
EDIT:
As static works fine, is good to know but it doesn’t answer my other questions