Cook and Package Fail. Error component attach, worked in previous versions

This is related to other bugs posted, such as link text:

I have tried packaging first, then cook. Also I have tired deleting Intermediate and saved folders, same fail on package and cook.

I have classes that extend UMarkerComp. They are used to help generate procedural content. There was no issue with them through 4.10.

Here is an excerpt, one of the errors:

MainFrameActions: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2016.05.25-05.09.59:321][ 0]LogSceneComponent:Error: Component ‘PickupMarker /Engine/Transient.TRASHCLASS_BaseBlockWorld1_299:PickupMarker_0’ has ‘BillboardComponent /Engine/Transient.TRASHCLASS_BaseBlockWorld1_299:PickupMarker_0.Billboard’ in its AttachChildren array, however, ‘BillboardCompon
ent /Engine/Transient.TRASHCLASS_BaseBlockWorld1_299:PickupMarker_0.Billboard’ believes it is attached to ‘PickupMarker /Script/JLemon.Default__PickupMarker’

Here is the header of the class:

#pragma once

#include "MarkerComp.h"
#include "PickupMarker.generated.h"

/**
 * 
 */
UCLASS(ClassGroup = (Lemon), meta = (BlueprintSpawnableComponent))
class JLEMON_API UPickupMarker :  UMarkerComp
{
	GENERATED_BODY()
	
:
    // Sets default values for this actor's properties
    UPickupMarker(const FObjectInitializer& ObjectInitializer);

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pickup")
	TSubclassOf< class ABasePickup > PickupSpawnClass;

    // Called when the game starts
    virtual void InitializeComponent() override;

    // Called every frame
    virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	
	
};

And here is the .cpp file:

// Fill out your copyright notice in the Description page of Project Settings.

#include "JLemon.h"
#include "PickupMarker.h"

// Sets default values
UPickupMarker::UPickupMarker(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
#if WITH_EDITOR
	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	bWantsInitializeComponent = true;
	PrimaryComponentTick.bCanEverTick = true;

    // Structure to hold one-time initialization
    struct FConstructorStatics
    {
        // A helper class object we use to find target UTexture2D object in resource package
        //TODO: Change Icon to PickupIcon
        ConstructorHelpers::FObjectFinder<UTexture2D> Texture0;
        FConstructorStatics()
            : Texture0(TEXT("Texture2D'/Game/Lemons/Procedural/Blocks/Blueprints/icons/AmmoMarker'"))
        {
        }
    };
    static FConstructorStatics ConstructorStatics;

    BillboardComponent = ObjectInitializer.CreateEditorOnlyDefaultSubobject<UBillboardComponent>(this, TEXT("Billboard"), true);

    SpriteTexture = ConstructorStatics.Texture0.Object;
    BillboardComponent->Sprite = SpriteTexture;

    BillboardComponent->AttachTo(this);
#endif
}

// Called when the game starts
void UPickupMarker::InitializeComponent()
{
    Super::InitializeComponent();

    // ...

}


// Called every frame
void UPickupMarker::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

    // ...
}

I commented out the code, again I can package.

But, it’s not a good solution as this worked all the way from 4.6 until now. It provided icons for the markers so could visually tell what type they were and it aided placement.

How are you supposed to change the icons of classes extending Marker?

Hello ,

I’m actually fairly surprised that this ever worked. Seeing as you’re doing all of this within “#if WITH_EDITOR”, none of it will ever be included in the packaged game. This also means that the FConstructorStatics struct will never be defined. You also may want to take this line out of “#if WITH_EDITOR” if you’re doing anything on tick with this class:

PrimaryComponentTick.bCanEverTick = true;

If any instances of this class are placed in the level when package, it’ll attempt to package them and then notice that they are referencing things that don’t exist (since they are only in the editor) and give you these errors.

Thanks, tonight I will try removing the In Editor only but the reason I had it was because of:

ObjectInitializer.CreateEditorOnlyDefaultSubobject<UBillboardComponent>(this, TEXT("Billboard"), true);

I only need the billboard sprite in the Editor, and it only needs to tick in Editor, to face the billboard. It shouldn’t care what it is when running the game.

This worked for more than a year until 4.10. It broke temporarily on a similar class extending Marker, but then started working again. It builds for other similar classes by the way, all with the same type of constructor code.

What is the correct way to change the sprite when extending a Marker component?

I didn’t think about this before, but one issue is that you’re calling AttachTo in the constructor. It’ll sometimes work, but it can cause some weird symptoms like this. In versions 4.11 and earlier, you’ll need to set AttachParent when attaching in the constructor. From 4.12 and onwards you would call SetupAttachment instead.

It has to use #if WITH_EDITOR, if you look in the base class UMarkerComp, BillboardComponent and SpriteTexter are declared within a #if WITH_EDITOR block.

So, it appears changing it from the function AttachTo to assigning the AttachParent directly allows it to build again.

Hello ,

Due to your latest comment, I’ve converted my previous comment into an answer as it seems like that change solved your problem. If my assumption is wrong, please let me know and we can continue.