[Crash][4.7.1] When calling USphereComponent::GetOverlappingActors instance method

When doing the tutorial “Introduction to UE4 Programming - 5 - Empowering the Character”, the editor started crashing every time when executing the pickup input action, which callbacks CollectBatteries method. The crash reportert says the problem is on the following line:

TArray collectedActors;

CollectionSphere->GetOverlappingActors(collectedActors); // <-- here

This is the declaration of the CollectionSphere variable:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Power, meta = (AllowPrivateAccess = "true"))

class USphereComponent *CollectionSphere;

and this is the initialization code:

CollectionSphere = CreateDefaultSubobject(TEXT("CollectionSphere"));

CollectionSphere->AttachTo(RootComponent);

CollectionSphere->SetSphereRadius(200.0f);

This is the action binding code:

InputComponent->BindAction("Pickup", IE_Pressed, this, &ACodeTutorialCharacter::CollectBatteries);

When the environment crashes, this is the crash report i get:

MachineId:903DE8F84C61EBD7E3B967B9E70D382A

Access violation - code c0000005 (first/second chance not available)

Ensure condition failed: false [File:D:\Programs\UnrealEngine-4.7.1\Engine\Source\Runtime\Engine\Private\SceneComponent.cpp] [Line: 914]
Template Mismatch during attachment. Attaching instanced component to template component. Parent 'CollisionC

UE4Editor_Engine!UPrimitiveComponent::GetOverlappingActors() + 79 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\primitivecomponent.cpp:2089]
UE4Editor_CodeTutorial!ACodeTutorialCharacter::CollectBatteries() + 85 bytes [d:\projects\unreal projects\codetutorial\source\codetutorial\codetutorialcharacter.cpp:154]
UE4Editor_Engine!UPlayerInput::ProcessInputStack() + 8096 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\userinterface\playerinput.cpp:1064]
UE4Editor_Engine!APlayerController::ProcessPlayerInput() + 94 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\playercontroller.cpp:2367]
UE4Editor_Engine!APlayerController::TickPlayerInput() + 1393 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\playercontroller.cpp:3728]
UE4Editor_Engine!APlayerController::PlayerTick() + 75 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\playercontroller.cpp:2045]
UE4Editor_Engine!APlayerController::TickActor() + 702 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\playercontroller.cpp:3801]
UE4Editor_Engine!FActorTickFunction::ExecuteTick() + 580 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\actor.cpp:119]
UE4Editor_Engine!FTickTaskSequencer::FTickFunctionTask::DoTask() + 214 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\ticktaskmanager.cpp:322]
UE4Editor_Engine!TGraphTask::ExecuteTask() + 445 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\core\public\async\taskgraphinterfaces.h:671]
UE4Editor_Core!FTaskThread::ProcessTasks() + 3109 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\core\private\async\taskgraph.cpp:428]
UE4Editor_Core!FTaskThread::ProcessTasksUntilQuit() + 77 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\core\private\async\taskgraph.cpp:271]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() + 511 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\core\private\async\taskgraph.cpp:984]
UE4Editor_Engine!FTaskGraphInterface::WaitUntilTaskCompletes() + 367 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\core\public\async\taskgraphinterfaces.h:188]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() + 432 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\ticktaskmanager.cpp:187]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() + 1182 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\ticktaskmanager.cpp:722]
UE4Editor_Engine!UWorld::RunTickGroup() + 102 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\leveltick.cpp:696]
UE4Editor_Engine!UWorld::Tick() + 2971 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\engine\private\leveltick.cpp:1114]
UE4Editor_UnrealEd!UEditorEngine::Tick() + 5618 bytes [d:\programs\unrealengine-4.7.1\engine\source\editor\unrealed\private\editor.cpp:1329]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() + 22 bytes [d:\programs\unrealengine-4.7.1\engine\source\editor\unrealed\private\unrealedengine.cpp:347]
UE4Editor!FEngineLoop::Tick() + 4179 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\launch\private\launchengineloop.cpp:2257]
UE4Editor!GuardedMain() + 1404 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() + 249 bytes [d:\programs\unrealengine-4.7.1\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

The problem appears to be kinda blocking, so i cannot really proceed further with the tutorials, where all others depends on the functionality of picking up an actor from the world.

Hi,

The assert seems to be complaining about component attachment in your constructor, which looking at the tutorial seems unrelated to the CollectBatteries() function (aside from it uses the component in question).

It looks like you should be calling ObjectInitializer.CreateDefaultSubObject(), rather than just CreateDefaultSubObject() to create your SphereComponent. This should create a ‘template’ component rather than an ‘instanced’ component in your constructor.

I have tested the solution you proposed before posting here, but it did not help me.

It is rather weird but I resolved the problem just by removing the code concerning the problematic component, and then reentering it again. Looks like the building tool did some miraculous things in the background.