I have a class called commoncharacter that has a few things in it, and from it I derive the player and the enemies. One of the common character’s components is a ChildActorComponent. I’m initializing the component in the constructor like so,
ChildActorComponent->SetupAttachment(GetMesh());
and this is the declaration
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
class UChildActorComponent* ChildActorComponent;
Then, in BeginPlay, I am trying to set the Chile Actor Class like so,
ChildActorComponent->SetChildActorClass(WeaponClassType);
WeaponClassType is a TSubclassOf. The issue I am getting with all of this is on the SetChildActorClass line. if I comment it out, no crash. If I don’t, crash. After a little digging, I found that the code was running through the constructor of commonCharacter 3 times, and each time the ChildActorComponent had a different memory address. Then, when it hits the SetChildActorClass, it says that the ChildActorComponent is NULL. I’m stumped on how it would go through the constructor 3 times and how the Component is ending up NULL? Is my problem with initializing the Component? Or could it be something else?