Failed Import UBoxComponent

Hello,

I’m encountering the following bug. My bot character has a UBoxComponent that is only used for collision done by touch (for mobile devices). The component is created with the ObjectInitializer.CreateDefaultSubobject().

When I place more that one bot actor in the level I get this error on launch. The funny part is that the bot that should be missing it, have their UBoxComponent initialized, visible in game and working during play. It’s like a false error report of some sorts.

I’m using the latest source version of the engine 4.7.3.

Hey -

What is the error message you get? Additionally, ObjectInitializer is no longer necessary when creating a component. Instead the call can be made with VariableName = CreateDefaultSubobject(TEXT("FriendlyName"));

Cheers

Hello ,

The error message I get says Failed Import for BoxComponent and then it links one of my placed bots in the level. I find this weird because as I said, the component is actually present on the bot and is working properly. Moreover, the bots also have a UBillboardComponent that’s created in the exact same way and I never had any issue with it.

Hey -

Getting a “Failed Import” error for something created in code seem confusing. How is the BoxComponent attached to the bot? Could you post the header and source file for the class where the boxcomponent is being created?

Hello , wasn’t available during the weekend so I just saw your reply.

Here’s the code for the box component. I’m also posting the code for a billboard component that works fine with no errors:

.h

protected:
	/** Touch Collision Box */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision, meta = (AllowPrivateAccess = "true"))
	class UBoxComponent* TouchBox;

public:
	FORCEINLINE class UBoxComponent* GetTouchBox() const { return TouchBox; }
};

/** Sprite used for the target lock */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Targeting)
UBillboardComponent* LockDecal;

.cpp

AThirdPersonShooterBot::AThirdPersonShooterBot(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer){
	AIControllerClass = AThirdPersonShooterBotController::StaticClass();
	static ConstructorHelpers::FClassFinder<UTPSWidget_EnemyHealth> WidgetClass(TEXT("/Game/UI/EnemyHealth.EnemyHealth_C"));
	if (WidgetClass.Class != NULL)
	{
		HealthWidgetClass = WidgetClass.Class;
	}
	GetMesh()->bReceivesDecals = false;

	TouchBox = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("TouchBox"));
	TouchBox->SetCollisionResponseToChannel(COLLISION_PROJECTILE, ECR_Overlap);
	TouchBox->SetCollisionResponseToChannel(COLLISION_WEAPON, ECR_Overlap);
	TouchBox->SetCollisionResponseToChannel(COLLISION_TOUCH, ECR_Block);
	TouchBox->AttachTo(RootComponent);
	TouchBox->SetRelativeScale3D(FVector(3.5, 1.0, 3.5));
	TouchBox->SetRelativeRotation(FRotator(0, 90, 0));
	// TEMP
	TouchBox->bHiddenInGame = false;


	LockDecal = ObjectInitializer.CreateDefaultSubobject<UBillboardComponent>(this, TEXT("LockGraphic"));
	LockDecal->AttachTo(RootComponent);
	LockDecal->bVisible = false;
	LockDecal->bHiddenInGame = false;

	// Parameter setting
	MaxHealth = 25;
	CurrentHealth = MaxHealth;
}

Hey -

There is a bit of code that seems specific to your project. Are you able to reproduce the bug in a new project with no additional content? If so what are the steps used to setup the boxComponent? Also, do you get the same error if you change the TouchBox from “protected” to “public”?

Hello , I wasn’t able to replicate this on an entirely new project but something interesting happened when I tried it on a previously existing one.

I thought that the said project was vanilla but it seems like I have added my own Character Movement Component to the Player Character. Here’s what happened

  1. Added a new C++ class based on Character and named it Bot
  2. Closed the editor and opened Visual Studio.
  3. Copy pasted the code for the Touch Component but this time I removed the AllowPrivateAcess and created the object without using the ObjectInitializer as you suggested above.
  4. Compiled and reopened the editor.
  5. Created a new blueprint based on Bot.h and set 3 of those guys in my scene.
  6. Closed the editor and opened it up again.
  7. On open I got a similar error stating that it Failed Import for my Character Movement Component on the Player’s Character present in the level.

This error only occurred after I set up those bots. I know it’s not a new project but it’s weird to get such an error after adding this component to a completely unrelated character.

P.S Also changing the component from protected to public doesn’t help as I’m still getting the same error.

Hey -

I tried following the steps in a first person and third person template with no error. If you are unable to reproduce the bug in a new project then the code for your bot may be interfering with code elsewhere. Would it be possible to send us a copy of the project where the bug is occurring? If you’re able to upload the project to dropbox you can send me a private message on the forums with a link. At minimum would it be possible to send the source and header files for the bot class you’re creating?

Cheers

Hey -

Sorry for the delay however I have the chance to test the project you sent me on the forums. I’m still not sure what is causing the error when opening the project (since the component seems to be working in game) but I did find that by changing it from a UBoxComponent to a USphereComponent the error went away and did not return when I set it back to a UBoxComponent. Try changing the component type in the code and let me know if you still get the same error when you save and reopen the project.

Cheers

Hello ,

Sometime in between code modifications the issue disappeared.