So I’ve been trying to figure out an issue for the last couple days. I have been trying to convert my BP into C++, and ran into a very peculiar issue when attempting to convert one of the variables to a C++ variable.
In the original setup, if I were to toggle the boolean “On Defense” within the editor, a shield would appear on the character, and if untoggled, it would disappear as expected.
“Shield Mesh BP” is a StaticMeshComponent created in Blueprints, and “Shield Mesh” is a UStaticMeshComponent* created in C++.
Below is an image of the BP part:
[SPOILER]
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
UStaticMeshComponent* ShieldMesh;
That is how the variable is declared in C++, if that helps.
“Setup Static Mesh Component” is defined in C++ as follows:
void AKolhiiCharacter::SetupStaticMeshComponent(USkeletalMeshComponent* SkelMesh, UStaticMesh* MeshToCreate, FName SocketToAttach, UStaticMeshComponent* &MeshToSet)
{
MeshToSet = NewObject<UStaticMeshComponent>(this);
MeshToSet->RegisterComponent();
MeshToSet->SetStaticMesh(MeshToCreate);
MeshToSet->AttachToComponent(SkelMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, SocketToAttach);
// Use this tag so GC occurs correctly
MeshToSet->CreationMethod = EComponentCreationMethod::UserConstructionScript;
}
As mentioned previously, changing “On Defense” with “Shield Mesh BP” attached to “Mesh To Set” will cause the shield to appear or disappear, but if it uses “Shield Mesh” instead, the editor crashes with the following:
Assertion failed: *Iter [File:D:\Build\++UE4+Release-4.14+Compile\Sync\Engine\Source\Editor\DetailCustomizations\Private\BodyInstanceCustomization.cpp] [Line: 180]
Full Dump:
[SPOILER]
Assertion failed: *Iter [File:D:\Build\++UE4+Release-4.14+Compile\Sync\Engine\Source\Editor\DetailCustomizations\Private\BodyInstanceCustomization.cpp] [Line: 180]
UE4Editor_Core!FDebug::AssertFailed() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:332]
UE4Editor_DetailCustomizations!FBodyInstanceCustomization::CustomizeChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\detailcustomizations\private\bodyinstancecustomization.cpp:181]
UE4Editor_PropertyEditor!FDetailPropertyRow::OnItemNodeInitialized() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailpropertyrow.cpp:229]
UE4Editor_PropertyEditor!FDetailItemNode::InitPropertyEditor() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailitemnode.cpp:98]
UE4Editor_PropertyEditor!FDetailItemNode::Initialize() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailitemnode.cpp:46]
UE4Editor_PropertyEditor!FDetailPropertyRow::GenerateChildrenForPropertyNode() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailpropertyrow.cpp:287]
UE4Editor_PropertyEditor!FDetailPropertyRow::OnGenerateChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailpropertyrow.cpp:239]
UE4Editor_PropertyEditor!FDetailItemNode::GenerateChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailitemnode.cpp:228]
UE4Editor_PropertyEditor!FDetailPropertyRow::GenerateChildrenForPropertyNode() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailpropertyrow.cpp:287]
UE4Editor_PropertyEditor!FDetailPropertyRow::GenerateChildrenForPropertyNode() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailpropertyrow.cpp:279]
UE4Editor_PropertyEditor!FDetailPropertyRow::OnGenerateChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailpropertyrow.cpp:239]
UE4Editor_PropertyEditor!FDetailItemNode::GenerateChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailitemnode.cpp:228]
UE4Editor_PropertyEditor!FDetailCategoryImpl::GenerateNodesFromCustomizations() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailcategorybuilderimpl.cpp:627]
UE4Editor_PropertyEditor!FDetailCategoryImpl::GenerateChildrenForSingleLayout() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailcategorybuilderimpl.cpp:649]
UE4Editor_PropertyEditor!FDetailCategoryImpl::GenerateChildrenForLayouts() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailcategorybuilderimpl.cpp:687]
UE4Editor_PropertyEditor!FDetailCategoryImpl::GenerateLayout() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detailcategorybuilderimpl.cpp:833]
UE4Editor_PropertyEditor!FDetailLayoutBuilderImpl::BuildCategories() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detaillayoutbuilderimpl.cpp:154]
UE4Editor_PropertyEditor!FDetailLayoutBuilderImpl::GenerateDetailLayout() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\detaillayoutbuilderimpl.cpp:189]
UE4Editor_PropertyEditor!SDetailsViewBase::UpdateSinglePropertyMap() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\sdetailsviewbase.cpp:382]
UE4Editor_PropertyEditor!SDetailsViewBase::UpdatePropertyMaps() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\sdetailsviewbase.cpp:347]
UE4Editor_PropertyEditor!SDetailsViewBase::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\sdetailsviewbase.cpp:1100]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:689]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_SlateCore!SPanel::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:19]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_Slate!SSplitter::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\widgets\layout\ssplitter.cpp:166]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_SlateCore!SPanel::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:19]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_Slate!SBox::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\widgets\layout\sbox.cpp:235]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_Slate!SBorder::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\widgets\layout\sborder.cpp:86]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SOverlay::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\soverlay.cpp:100]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_SlateCore!SPanel::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:19]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_Slate!SSplitter::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\widgets\layout\ssplitter.cpp:166]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_Slate!SSplitter::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\widgets\layout\ssplitter.cpp:166]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SOverlay::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\soverlay.cpp:100]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_SlateCore!SPanel::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:19]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_Slate!SBorder::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\widgets\layout\sborder.cpp:86]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SOverlay::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\soverlay.cpp:100]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_SlateCore!SPanel::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:19]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_Slate!SSplitter::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\widgets\layout\ssplitter.cpp:166]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SOverlay::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\soverlay.cpp:100]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_SlateCore!SPanel::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:19]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SPanel::PaintArrangedChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:44]
UE4Editor_SlateCore!SPanel::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\spanel.cpp:19]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SOverlay::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\soverlay.cpp:100]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_SlateCore!SCompoundWidget::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\scompoundwidget.cpp:25]
UE4Editor_SlateCore!SWindow::OnPaint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swindow.cpp:1809]
UE4Editor_SlateCore!SWidget::Paint() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slatecore\private\widgets\swidget.cpp:692]
UE4Editor_Slate!FSlateApplication::DrawWindowAndChildren() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:1127]
UE4Editor_Slate!FSlateApplication::PrivateDrawWindows() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:1367]
UE4Editor_Slate!FSlateApplication::DrawWindows() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:1084]
UE4Editor_Slate!FSlateApplication::TickApplication() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:1689]
UE4Editor_Slate!FSlateApplication::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:1481]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2894]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launch.cpp:152]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll
[/SPOILER]
Interestingly enough, if the “On Defense” flag is applied prior to changing the variable connection, it is possible to toggle between having the shield and not having it without a problem. But saving the file when it is unchecked afterwards crashes the engine in the same way as above. So it has something to do with how the editor treats a changing C++ variable compared to a changing BP one (I’m assuming it’s specific to Components). I’m not sure if the BP version has some intrinsic initializer or something.
If it helps at all, the following is done in OnConstruction without a problem:
[SPOILER]
// This is the C++ equivalent to the BP Construction Script (so the BP values should already exist, unlike in the standard constructor)
void AKolhiiCharacter::OnConstruction(const FTransform& Transform)
{
// Always remember to call Super!
Super::OnConstruction(Transform);
USkeletalMeshComponent* SkelMesh = GetMesh();
// Setup Body Materials
SetupMaterial(SkelMesh, 0, BodyArmMatSource, BodyColor, ArmColor, BodyArmMat);
SetupMaterial(SkelMesh, 1, HandHipFootMatSource, HandFootColor, HipColor, HandHipFootMat);
SetupMaterial(SkelMesh, 2, EyeGearHeadNeckMatSource, FColor::White, EyeColor, EyeGearHeadNeckMat);
// Setup Mask
SetupStaticMeshComponent(SkelMesh, MaskMeshSource, "MaskSocket", MaskMesh);
SetupMaterial(MaskMesh, 0, MaskMatSource, MaskColor, FColor::Black, MaskMat, "Color", "None");
// Setup Stick
SetupStaticMeshComponent(SkelMesh, StickMeshSource, "StickSocket", StickMesh);
// Setup Armor
SetupStaticMeshComponent(SkelMesh, ArmorMeshSource, "Shoulder_LSocket", LeftArmorMesh);
SetupStaticMeshComponent(SkelMesh, ArmorMeshSource, "Shoulder_RSocket", RightArmorMesh);
SetupArmorMaterial();
// Setup Shield (hopefully I can figure that problem out)
//if (bOnDefense)
//{
// SetupStaticMeshComponent(SkelMesh, ShieldMeshSource, "ShieldSocket", ShieldMesh);
// Set materials
//}
}
[/SPOILER]
I don’t believe it’s strictly necessary that I use the construction script (or rather OnConstruction(), once I get this working or deem it impossible), but I’m unsure why BP variables are being treated differently from C++ variables of the same type, and I’d like to know why if possible.
Thank you for any insight that can be provided. And feel free to ask if you need more information. Oh, and let me know if this is in the wrong place, I’m not quite sure because this is both a C++ and BP issue, as far as I can tell.