The editor runs the ActorComponent fine the first time I hit play, but if I hit play a second time the editor crashes. I have BeginPlay implemented on the abstract Base class, and subclasses since if I print to the output log the editor doesn’t crash. (Code shown doesn’t have it)
The base class:
typedef TFunction<FName(void)> Condition;
typedef TArray<FName> BranchValues;
typedef TUnion<BranchValues, Condition> BranchTypes;
#define LOCTEXT_NAMESPACE "Dialogue"
USTRUCT()
struct FDialogueNodes
{
GENERATED_BODY()
FText DialogueFragment;
BranchTypes branch;
FDialogueNodes() {}
FDialogueNodes(FText dialogueFragment, TArray<FName> nextNode)
: DialogueFragment(dialogueFragment)
{
branch.SetSubtype<BranchValues>(nextNode);
}
FDialogueNodes(Condition condition)
{
branch.SetSubtype<Condition>(condition);
}
FDialogueNodes(FText dialogueFragment)
: DialogueFragment(dialogueFragment)
{
branch.SetSubtype<BranchValues>(BranchValues());
}
};
UCLASS(abstract)
class DIALOGUES_API UBaseDialogue : public UActorComponent
{
GENERATED_BODY()
public:
UBaseDialogue();
virtual void BeginPlay() override;
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
//... BlueprintCallable methods
protected:
FName id;
};
Child class header:
UCLASS(ClassGroup=(Dialogue), meta=(BlueprintSpawnableComponent))
class DIALOGUES_API UBanter2afterthespiders : public UBaseDialogue
{
GENERATED_BODY()
public:
UBanter2afterthespiders();
virtual void BeginPlay() override;
virtual void OnRegister() override;
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
private:
IGameTime *gameTime;
};
Child class Cpp:
UBanter2afterthespiders::UBanter2afterthespiders()
{
}
void UBanter2afterthespiders::OnRegister()
{
Super::OnRegister();
id = TEXT("0x01000001000000DC");
gameTime = NewObject<AGameTimeImplementation>();
Condition c_0 = [this](void)->FName{ return (gameTime->Hour() < 19) ? TEXT("0x01000001000000D4") : TEXT("0x01000001000000E2"); };
// Emplace 24 elements in dialogues TMap.
}
void UBanter2afterthespiders::BeginPlay()
{
Super::BeginPlay();
}
void UBanter2afterthespiders::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction *ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
I don’t think there’s really any reason to have TickComponent, or BeginPlay on these classes. (Works fine the first time I hit play without crashing) I’ve tried tons of things from manually deleting Interfaces, to migrating my Interfaces to Unreal’s implementation of interfaces. I also tried changing where Banter2afterthespiders intializes it’s values from the Constructor to OnRegister.
memreport shows memory usage growing slightly bewteen the first play and second play, I have a feeling that my c_0 TFunction isn’t being garbage collected, but I’m not sure how to either delete a TFunction manually or allow for a Union to be garbage collected. If anyone is able to help me figure out what’s causing the crash I’d appreciate it greatly.
Crash Log The Crash Log isn’t always the same.