Critical Error SceneComponent Object from PIE level still referenced. Shortest path from root

I just don’t know.

Here is the important (i think) part of log:

D:\BuildFarm\buildmachine_++depot+UE4-Rocket+Beta6\Engine\Source\Developer\MessageLog\Private\Model\MessageLogListingModel.cpp(70):
Fatal error: Critical Error
SceneComponent
/Game/Maps/UEDPIE_0_Example_Map.TheWorld:PersistentLevel.Ability1_C_1.DefaultSceneRoot
Object from PIE level still
referenced. Shortest path from root:
SceneComponent
/Game/Maps/UEDPIE_0_Example_Map.TheWorld:PersistentLevel.Ability1_C_1.DefaultSceneRoot
[target] Ability1_C
/Game/Maps/UEDPIE_0_Example_Map.TheWorld:PersistentLevel.Ability1_C_1
(ObjectProperty
/Game/Blueprints/Ability1.Ability1_C:DefaultSceneRoot)
MyCharacter2_C
/Game/Maps/UEDPIE_0_Example_Map.TheWorld:PersistentLevel.MyCharacter2_C_0
(ObjectProperty
/Game/Blueprints/MyCharacter2.MyCharacter2_C:CallFunc_BeginSpawningActorFromBlueprint_ReturnValue_11218291414BF58BB3904D90EF49316F)
EffectTest_C
/Game/Blueprints/EffectTest.Default__EffectTest_C
(ObjectProperty
/Script/RPG.RPGEffectBase:CausedBy)
Blueprint
/Game/Blueprints/EffectTest.EffectTest
(root) (standalone) (ClassProperty
/Script/Engine.BlueprintCore:GeneratedClass)

This happen while I close game window in editor.
From what I understand it complains that there still referenced object inside world. It didn’t happen before, only after I added my FTimerManager to the code. So my first though was it was the case, so I just removed all traces of it from code and it still happen. It was clearly not an issue.

Here is all relevant code:

RPGEffectManagerComponent:

void URPGEffectManagerComponent::AddEffect()
{
	//NewEffect->SelfRemove();
	EffectsList.Add(NewEffect);
}


UCLASS(meta=(BlueprintSpawnableComponent))
class URPGEffectManagerComponent : public UActorComponent
{
	GENERATED_UCLASS_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=EffectList)
	TArray EffectsList;

	URPGEffectBase* NewEffect;

	void AddEffect();
	
};

Blueprint function for adding:

void URPGEffectBPLibrary::ApplyEffect(AActor* effectTarget, AActor* causedBy, TSubclassOf appiledEffect)
{
	ARPGCharacter* GC = Cast(effectTarget);
	if(GC)
	{
		if(appiledEffect)
		{
			//static ConstructorHelpers::FObjectFinder spawnEffect (appiledEffect.Class);
			//GC->EffectManager->EffectsList.Add(appiledEffect.GetDefaultObject());
			//appiledEffect->effectManager = GC->EffectManager;
			URPGEffectBase* effect = appiledEffect.GetDefaultObject();
			effect->AffectedTarget = effectTarget;
			effect->CausedBy = causedBy;
			
			GC->EffectManager->NewEffect = effect;
			GC->EffectManager->AddEffect();
		}
	}
}

I assume I should delete all references while closing my PIE mode.
Two questions:

  1. Where exactly should I destroy them ?
  2. Is there any reason why it worked before and now after reverting the state when it worked it doesn’t work. Ok. it’s bit convoluted and I don’t really expect straight answer in any case (;.

Full log in attachment.link text

I narrowed issue to this:
void URPGEffectBPLibrary::ApplyEffect(AActor* effectTarget, AActor* causedBy, TSubclassOf appiledEffect)
{
ARPGCharacter* GC = Cast(effectTarget);
if(GC)
{
if(appiledEffect)
{
//static ConstructorHelpers::FObjectFinder spawnEffect (appiledEffect.Class);
//GC->EffectManager->EffectsList.Add(appiledEffect.GetDefaultObject());
//appiledEffect->effectManager = GC->EffectManager;
URPGEffectBase* effect = appiledEffect.GetDefaultObject();
effect->AffectedTarget = effectTarget;
effect->CausedBy = causedBy;

			//GC->EffectManager->NewEffect = effect;
			GC->EffectManager->SetNewEffect(effect);
			GC->EffectManager->AddEffect();
		}
	}
}

More specific to these lines of code:
effect->AffectedTarget = effectTarget;
effect->CausedBy = causedBy;

			//GC->EffectManager->NewEffect = effect;
			GC->EffectManager->SetNewEffect(effect);
			GC->EffectManager->AddEffect();
		}

When I use this:
GC->EffectManager->EffectsList.Add(appiledEffect.GetDefaultObject());

It’s working. But it’s only half-baked solution.
Just to be clear. In both cases the effect is the same. The objects are added to the array.

edit:

After closer examinations it seems like

		appiledEffect.GetDefaultObject()->AffectedTarget = effectTarget;
		appiledEffect.GetDefaultObject()->CausedBy = causedBy;

Assigning fields from function input causes, well something bad.

You should never be manipulating the default object of a given class. I think your problem will go away if you change

URPGEffectBase* effect = appiledEffect.GetDefaultObject();

to

URPGEffectBase* effect = ConstructObject();

Thanks. It helped!