Crash on TargetComponent.cpp line 31
How to reproduce: I have a AActor with a Target component and a method called Die(). If I set a SetLifespan to remove the actor from the scene after it dies, the game goes on but when you hit esc to stop the simulation/play in viewport, it crashes in TargetComponent.cpp line 31.
Here's the crash report:
LoginId:e8a1a7f24dc66d495ebf968a08e3cf9b EpicAccountId:c40bbf764741428c85a49fd30146ff5d
Assertion failed: GetWorld() [File:D:\build\U5M-Marketplace\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\LockOnTarget\Source\LockOnTarget\Private\TargetComponent.cpp] [Line: 31]
UnrealEditor_LockOnTarget!UTargetComponent::EndPlay() [D:\build\U5M-Marketplace\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\LockOnTarget\Source\LockOnTarget\Private\TargetComponent.cpp:78] UnrealEditor_Engine!UActorComponent::BeginDestroy() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\ActorComponent.cpp:690] UnrealEditor_CoreUObject!UObject::ConditionalBeginDestroy() [D:\build++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp:1175] UnrealEditor_CoreUObject!UnhashUnreachableObjects() [D:\build++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\GarbageCollection.cpp:4837] UnrealEditor_CoreUObject!UE::GC::CollectGarbageImpl<1>() [D:\build++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\GarbageCollection.cpp:4736] UnrealEditor_CoreUObject!UE::GC::CollectGarbageFull() [D:\build++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\GarbageCollection.cpp:4538] UnrealEditor_CoreUObject!CollectGarbage() [D:\build++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\GarbageCollection.cpp:4887] UnrealEditor_UnrealEd!UEditorEngine::EndPlayMap() [D:\build++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:478] UnrealEditor_UnrealEd!UEditorEngine::Tick() [D:\build++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:2244] UnrealEditor_UnrealEd!UUnrealEdEngine::Tick() [D:\build++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:531] UnrealEditor!FEngineLoop::Tick() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5825] UnrealEditor!GuardedMain() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188] UnrealEditor!GuardedMainWrapper() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:118] UnrealEditor!LaunchWindowsStartup() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:258] UnrealEditor!WinMain() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:298] UnrealEditor!__scrt_common_main_seh() [D:\a_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288] kernel32 ntdll
Hello, could you provide a little more information about the setup. Wasn't able to reproduce the issue in UE 5.1 (Debug, Development, Shipping editor builds). It's also a bit of a weird callstack since components should be destroyed by the owning actor.
Does this only happen with SetLifeSpan() or with basic DestroyActor() too? Also for testing, try to manually call CollectGarbage() after destroying the target.
Hi! About the setup: Using Unreal 5.3.2. Project is using C++ Enemy actor child to another class called BaseCharacter. In blueprint I added the target component to the Enemy and it works great with the LockOnTarget of the HeroClass. I spawned a new map with some actors, and as the enemy died this function was called:
void ABaseCharacter::Die() { DisableCapsule(); // remove collision from capsule component SelectDeathMontage(); Tags.Add(FName("Dead")); SetLifeSpan(DeathLifeSpan); //10 seconds by default }
Replace all the lines above with void ABaseCharacter::Die() { //DisableCapsule(); //SelectDeathMontage(); //Tags.Add(FName("Dead")); Destroy(); } The problem persisted.
Here's a short clip https://streamable.com/43fixj
Tried to add CollectGarbage() after the Destroy() call and that crashed the game even before I hit ESC to exit, but I don't know if it's related to your plugin. I never had to call manually the garbage collector after destroying one actor I'm not sure if its safe to do this in the project.
Hi, I've tested it in 5.3 with a similar setup and everything works fine. You probably forgot to call the super method in your EndPlay() or something like this, cause the component isn't able to access the world.
Ok Man, thanks will test it later.