New C++ class wizard creates classes that crash the editor by default

The New C++ Class… wizard in the editor produces initially incomplete classes that can crash the editor. My assumption is that such new class stubs are intended to work properly with the engine (at least not cause crashes) even with no single line of code added?

The problem is that the classes produced by the wizard do not have a root component, and the editor occasionally dereferences the AActor::RootComponent pointer without checking whether it is non-null. One such dereference happens at:

actoreditorutils.cpp:77:
for (auto* ChildComponent : InActor->GetRootComponent()->AttachChildren),

which is triggered at least when moving an actor between folders in the World Outliner.

Repro

  1. Create a blank C++ project
  2. Create a new C++ class with Actor as the base class
  3. Compile and relaunch the editor
  4. Drop an instance of the newly created class into the world
  5. Create a new folder in the World Outliner
  6. Try to move the newly created instance into that folder

The editor will crash (see stack trace at the end).

Suggestion

In addition to adding a null pointer check to actoreditorutils.cpp:77, it might be useful to have the new class wizard to add a dummy root component in the constructor to new classes, possibly together with a comment line encouraging the user to replace it with whatever is eventually needed. This way all new actors become also editor-movable already from the start, instead of being invisible and non-selectable (and crash-prone) in the editor viewport.

Stack trace

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

“”

UE4Editor_Engine!FActorEditorUtils::TraverseActorTree_ParentFirst() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\engine\private\actoreditorutils.cpp:77]
UE4Editor_SceneOutliner!SceneOutliner::FFolderDropTarget::OnDrop() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\editor\sceneoutliner\private\foldertreeitem.cpp:141]
UE4Editor_SceneOutliner!SceneOutliner::FFolderTreeItem::OnDrop() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\editor\sceneoutliner\private\foldertreeitem.cpp:335]
UE4Editor_SceneOutliner!SceneOutliner::HandleDrop() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\editor\sceneoutliner\private\soutlinertreeview.cpp:101]
UE4Editor_SceneOutliner!SceneOutliner::SSceneOutlinerTreeRow::OnDrop() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\editor\sceneoutliner\private\soutlinertreeview.cpp:161]
UE4Editor_Slate!::operator()() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4313]
UE4Editor_Slate!FEventRouter::Route >() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:214]
UE4Editor_Slate!FSlateApplication::RoutePointerUpEvent() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4316]
UE4Editor_Slate!FSlateApplication::ProcessMouseButtonUpEvent() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4660]
UE4Editor_Slate!FSlateApplication::OnMouseUp() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4638]
UE4Editor_Core!FWindowsApplication::ProcessDeferredMessage() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\private\windows\windowsapplication.cpp:1403]
UE4Editor_Core!FWindowsApplication::DeferMessage() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\private\windows\windowsapplication.cpp:1708]
UE4Editor_Core!FWindowsApplication::ProcessMessage() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\private\windows\windowsapplication.cpp:706]
UE4Editor_Core!FWindowsApplication::AppWndProc() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\private\windows\windowsapplication.cpp:628]
user32
user32
UE4Editor_Core!FWindowsPlatformMisc::PumpMessages() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\private\windows\windowsplatformmisc.cpp:884]
UE4Editor!FEngineLoop::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\launch\private\launchengineloop.cpp:2392]
UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]

Hello hiili,

Thank you for your report. This is currently a known bug with version 4.9.2, and is entered in our database as UE-21194.

Have a great day,

Sean Flint