Error says: root component is a template component, obviously you need both components to be templates or instances. You need to show information about how RootComponent is initialized and how Capsule Component is created.
Y me too, try to change your component’s specifiers, for example remove VisibleDefaultsOnly.
As i understand template component is a component which has flags RF_ArchetypeObject|RF_ClassDefaultObject.
UPD: i’ve tested UPROPERTY specifiers, they doesnt affect. Well, i suppose the problem is somewhere in blueprint, may be you instantiate SpawnBoxComponent somewhere or smth like that. Because i’ve tested to attach the same box to the same capsule and everything is fine. I am using UE4.4.1.
UPD2: if i create SpawnBoxComponent or CapsuleComponent without using any blueprints it is still IsTemplate()==false. So, afterall, i think the problem is about how UE4 engine using ANavigationObjectBase inside engine and why Capsule component is becoming Template for this object. Component is not supposed to be Template by default i think.
The question is what is Template Componnt and how it did become a Template.
Couple of shot gun answers to various things in the thread:
As was mentioned AttachParent should be used when setting up your components in the constructor because it will do the AttachTo and all the associated actions when the components get registered. Doing AttachTo in the constructor will generally not get you what you want.
Template component simply means that it is a component that belongs to the Class Default Object, which is the prototype/template object from which other instanced objects get their properties initialized from.
The ensure message means that when the attachment is being executed your SpawnBox component is trying to attach itself to the component in the CDO, not its own instanced version.
I tried to reproduce this ensure by creating a new subclass of ANavigationObjectBase and just putting in the subobject pointer as in WCode’s post, but I couldn’t reproduce it. It probably shouldn’t cause an issue, but try taking the space out of the name of the component?
If you’re able to isolate the problem down to a simple repro in a new project, please do post on answerhub and attach the project.
Turns out it only happens when you place the custom PlayerStart in the world, then copy-paste it to make several instances. This process is fine with normal PlayerStart objects, but when you try to add your own components like I have above, and then copy-paste that custom PlayerStart, it crashes when PIE (haven’t tested standalone).
This is still present in unreal (4.24), so going to post this for future reference - compile and resaving the blueprint that the actor was generated from will fix this error. Would be great if unreal could warn about this kind of issue in a more understandable way.