Summary of issues:
Issue 1) Attaching a child component (eg: SphereComponent) from C++ code to an Actor’s root in 4.8 results in an error on PIE with the message
Template Mismatch during attachment. Attaching instanced component to template component. Parent 'SceneRoot' Self 'MyTrigger'
Issue 2) Even if the first issue is bypassed through a workaround, Overlap events are not triggered for attached collision components. Attaching a similar sphere component through the Blueprint components screen works perfectly so this issue appears limited to C++. IIRC, various issues with overlap events in 4.8 have been reported by others as well.
Note: The workaround needed to fix issue 1 involves moving attachment of the child component from the constructor to PostInitializeComponents (as attaching from the constructor causes the template mismatch error).
Issue 3) Issue #2 can be fixed by recompiling the blueprint in question and launching PIE again. This time, all overlap events work, however once the PIE session is closed the editor crashes with the following message:
Fatal error:
Critical Error BillboardComponent /Game/ThirdPersonBP/Maps/UEDPIE_0_ThirdPersonExampleMap.ThirdPersonExampleMap:PersistentLevel.GameNetworkManager_1.Sprite Object from PIE level still referenced. Shortest path from root: (Object is not currently rooted)
Repro project links:
All three issues are reproducible with blank template projects and some simple code for attaching a sphere component.
Issue #1 - https://drive.google.com/file/d/0BwBa98V8pf2sRC14ZmppUjZVWkU/view?usp=sharing
Issue #2 and #3 - https://drive.google.com/file/d/0BwBa98V8pf2sUkFfd1lPR2k3OXc/view?usp=sharing
In both projects take a look at the AMyActor C++ classes and MyActor Blueprint (which has been dropped into the level). Launching PIE should crash the first project (issue #1). The second project will launch PIE but overlap events won’t be triggered for MyActor (issue #2). Recompile the MyActor blueprint and run PIE again, this time the editor will crash after PIE exits (issue #3)
I’ve posted a single bug report for these issues as I get the feeling they’re coupled with each other, am happy to raise separate reports for each of these if that’s preferred though.
Code snippets
A quick look at code for each issue follows:
Issue #1:
AMyActor::AMyActor(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = true;
SceneComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneRoot"));
RootComponent = SceneComponent;
MyTrigger = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("MyTrigger"));
MyTrigger->AttachParent = RootComponent;
}
Issue #2, #3:
AMyActor::AMyActor(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = true;
SceneComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneRoot"));
RootComponent = SceneComponent;
MyTrigger = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("MyTrigger"));
}
void AMyActor::PostInitializeComponents()
{
// THIS IS A WORKAROUND FOR ISSUE #1 - Attaching in the constructor causes template mismatch issue
MyTrigger->AttachTo(RootComponent);
Super::PostInitializeComponents();
}
Thanks for looking, this is preventing me from moving on to 4.8 so can’t wait to get past the issues!