Adding UBoxComponent to a custom PlayerStart class crashes gameplay

Hey guys,

So I’ve extended APlayerStart with my own, AShipStart, from which I inherit to create the blueprint BP_ShipStart.

I’m adding a UBoxComponent to it, which I’m using as a sort of spawn zone that must be clear of players before it’s considered valid/usable.

.h:

UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Components)
TSubobjectPtr<UBoxComponent> SpawnBoxComponent;

.cpp

AShipStart::AShipStart(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	SpawnBoxComponent = PCIP.CreateDefaultSubobject<UBoxComponent>(this, "Spawn Box");
	SpawnBoxComponent->SetWorldScale3D(FVector(200, 200, 200));
	SpawnBoxComponent->AttachTo(RootComponent);
}

After this, when I open the editor I get a message about a ‘bad component’ with reference to the above UBoxComponent.

Error Failed import: BoxComponent
/Game/Blueprints/Core/BP_ShipStart.Default__BP_ShipStart_C:Spawn
Box in /Game/Maps/Default_Map

It also often crashes when hitting ‘Play’ in the editor.

Ensure condition failed: false
[File:F:\P4_BH_Home\UnrealEngine\Engine\Source\Runtime\Engine\Private\SceneComponent.cpp]
[Line: 744] Template Mismatch during
attachment. Attaching instanced
component to template component.
Parent ‘CollisionCapsule’ Self ‘Spawn
Box’ UE4Editor.exe has triggered a
breakpoint.

Any ideas? Never encountered this before.

(Post is clone of forum thread here. Forgot to say there that I’m using the source-built preview build 2289630).

Hi ,

I tried to reproduce this issue, and was only partially successful. When I first created the custom player start class, I received a slightly different error message when I opened the project in the Editor. However, every time I opened the project after that, there was no error message. I also did not see any crash in PIE.

Have you added any other code in your custom player start class? If not, could you post the full code in your header and code files so I can make sure mine matches what you have?

Hi ,

Yes I have added some other code to the player start, but they have nothing to do with components (and have been perfectly fine until adding the UBoxComponent).

Hi ,

Sorry my last reply was vague - I was in a rush.

I’ve narrowed down the problem to a specific, reproducible scenario. See the attached/linked project (was built with Preview Build 2289630); https://drive.google.com/file/d/0B6wtQNL4MWucVHcyck1OZ084dEU/edit?usp=sharing

If you open up the editor to the MyMap level and place a single BP_MyPlayerStart object, it works fine. If you copy-paste that object in the world so there are two of them (as opposed to dragging another in from the Content Browser), it also works fine.
If you do the same with BP_MyPlayerStartWithBox, it works with one, but then copy-pasting it to make a second, you’ll get the crash I posted above when PIE. For some reason, this copy-paste process fails with a PlayerStart that has the UBoxComponent attached in its constructor.

Hope this helps!

EDIT: I should note that I haven’t yet tested this in a standalone build/executable.

Thank you for providing a project to reproduce this issue. Unfortunately I was unable to trigger a crash, though I did notice a couple things. If I opened the project by double-clicking on the .uproject file and placed a couple of the BP_MyPlayerStartWithBox items in the level, using copy/paste for the second one, there was a definite pause when I clicked Play the first time. The pause lasted for a few seconds, then everything returned to normal. Any subsequent times that I clicked Play, the Editor immediately went into PIE mode.

I also tried opening the project using Visual Studio’s debugger. In this instance, I also did not see a crash, though whenever I clicked Play there were a couple Breakpoints that were triggered. Clicking Continue on each one allowed me to return to PIE mode in the Editor.

I tested this on our internal version of build 2289630. It is possible, though unlikely, that there may be a slight difference in the builds which prevented me from seeing the crash you described. Are you able to see the same crash with the latest preview build on GitHub (2302215)?

A few questions for clarification:

  • What Configuration and Platform settings were you using in Visual Studio when you built the project?
  • What is the exact method you used to copy/paste the second BP_MyPlayerStartWithBox (Did you right-click on the object in the display window, did you right-click on the object in the Scene Outliner, did you use Ctrl-C/Ctrl-V or the Edit menu in the Editor, or some combination of these)?
  • Did you get a callstack when the crash occurred?
  • Could you provide the logs for the project immediately after the crash occurs?

Hey -

I wanted to check with you if you are still receiving this crash when adding a box component to a custom player start with the latest engine version? We will continue to investigate the cause, let us know if you have any other questions or extra information.

Cheers

Hi ,

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

Hi
I (still) experience the same problem as , though with different objects. I don’t get a PIE gameplay crash, but a triggered breakpoint that allows me to click Continue and everything seems to work fine from there. But it’s still a little unsettling and annoying. Could you help me work this out?

I have a custom Actor object that creates two UGeneratedMeshComponent objects via ObjectInitializer.CreateDefaultSubobject() (based on the Procedural Mesh Component from A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums ).
In the Actor’s constructor, it sets one GeneratedMeshComponent as RootComponent. The other GeneratedMeshComponent’s AttachParent is set to the first GeneratedMeshComponent.
Some lines from the constructor code:

WaterMesh = ObjectInitializer.CreateDefaultSubobject<UGeneratedMeshComponent>(this, TEXT("GeneratedLowPolyWaterMesh"));
	TerrainMesh = ObjectInitializer.CreateDefaultSubobject<UGeneratedMeshComponent>(this, TEXT("GeneratedLowPolyTerrainMesh"));
RootComponent = WaterMesh;
TerrainMesh->AttachParent = WaterMesh;

I am currently trying to debug this and finding the root cause.
The ensureMsgf() that triggers the break is in SceneComponent.cpp.
There, Parent->IsTemplate() is true while IsTemplate() is false. This means that the parent object is a template, and the child object is not.
Interestingly, the same error message/breakpoint is triggered if I switch the attaching part in the code (if I attach object 1 to object 2 instead of object 2 to object 1).
The IsTemplate function returns true if any of the TemplateTypes flags (RF_ClassDefaultObject or RF_ArchetypeObject) are set.
Breakpoints in the engine code where such flags are set are not hit. How can these flags even be set if the corresponding SetFlags() function with RF_ClassDefaultObject or RF_ArchetypeObject is never even called?

I’m still trying to boil it down to a very simple case. If you’ve got any ideas on how to debug this please let me know.

I’m using Version 4.6.1

Hey TaurusI76-

The breakpoint you’re referring to that gets triggered is different from the crash originally reported. The editor is able to handle the ensureMsgf() call which is why the breakpoint is only triggered in Visual Studio and you can continue past it.

Because you are experiencing a different issue than I would suggest opening a new post with the information provided as well as any additional info related to how your actors are setup or used in your project.

Cheers