Download

Component instiantiated in editor goes missing randomly

I have a trigger component that performs certain actions once something overlaps with a primitive component it adds

code goes like this (relevant parts)



UCLASS(Blueprintable, editinlinenew, BlueprintType, ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class TWINSTICK_API UTriggerOnProximity : public UDynObjTriggerBase
{
	GENERATED_BODY()

public:
	UTriggerOnProximity(const FObjectInitializer& ObjectInitializer);

#if WITH_EDITOR
	virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#endif

private:
	/**
	* Component used for detection
	*/
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "DetectionMesh")
	class UShapeComponent* DetectionMesh;






#if WITH_EDITOR

void UTriggerOnProximity::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
	if (IsValid(DetectionMesh) && DetectionMesh->AttachParent != this)
	{
		DetectionMesh->AttachTo(this, NAME_None, EAttachLocation::SnapToTarget, false);
		DetectionMesh->RegisterComponent();

		DetectionMesh->OnComponentBeginOverlap.AddDynamic(this, &UTriggerOnProximity::OnDetectionOverlapBegin);
		DetectionMesh->OnComponentEndOverlap.AddDynamic(this, &UTriggerOnProximity::OnDetectionOverlapEnd);
	}
}
#endif


Everything works fine, I get to set up the detection component from the editor, get it’s overlaps and everything. Problem is, after working for a while, I notice objects I have set up no longer have the detection component and the property for it in the editor is reverted to “none”. Can anyone direct me at what I’m doing wrong?

I made a workaround by making the class fetch it’s child components on beginplay and work with them instead of creating it’s own, but I’d still love to know why I’m having problems with this.