SubComponents of a custom Component not updating correctly in editor

I am trying to create a custom USceneComponent with several UBoxComponent subcomponents:

/** .h **/
#pragma once
 
#include "Components/SceneComponent.h"
#include "MySceneComponent.generated.h"
 
/**
 *
 */
UCLASS(meta=(BlueprintSpawnableComponent))
class COMPONENTTEST_API UMySceneComponent : public USceneComponent
{
        GENERATED_UCLASS_BODY()
 
        UPROPERTY()
        TSubobjectPtr<UBoxComponent> Body;
       
};
 
 
/** .cpp **/
#include "ComponentTest.h"
#include "MySceneComponent.h"
 
 
UMySceneComponent::UMySceneComponent(const class FPostConstructInitializeProperties& PCIP)
        : Super(PCIP)
{
        Body = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Body"));
        Body->SetBoxExtent(FVector(10, 10, 10));
        Body->AttachTo(this);
        Body->bHiddenInGame = false;
}

I then create an Actor blueprint (not a custom class) and set this component as the root component and a static mesh child for reference.

Behavior:

  1. The box wireframe does not update its position in the editor when moving the actor around.
  2. In simulate it will show up in the correct initial position, but it will again not update when moved around

In play and launch I tested by adding a tick update that increase the relative position of the component.

  1. In play the mesh and wireframe move, but there is still a wireframe box where it started
  2. In launch everything seems correct
  3. After adding the tick, a trail of box wireframes are left behind when moving the actor.

Am I doing something wrong when creating a subcomponent, or is this a bug?

Hi ,

Could you provide a little more information about this issue?

  • What version of the Engine are you using, and are you using the binary version installed by the Launcher or did you build the Engine from source code?
  • Can you provide more information about how you are setting up your Blueprint to move when playing?

I was able to see the initial behavior that you mentioned, but I have not been able to get the box component to move at all when playing the game.

Hi ,

What version of the Engine are you
using, and are you using the binary
version installed by the Launcher or
did you build the Engine from source
code?

I am using the binary build, version 4.4.0.

Can you provide more information about
how you are setting up your Blueprint
to move when playing?

For movement, I add a child BoxComponent (to MySceneComponent) and turn off “Hidden in Game”. My updated files:

/** .h **/


#pragma once

#include "Components/SceneComponent.h"
#include "MySceneComponent.generated.h"

/**
 * 
 */
UCLASS(meta=(BlueprintSpawnableComponent))
class COMPONENTTEST_API UMySceneComponent : public USceneComponent
{
	GENERATED_UCLASS_BODY()

	virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Colliders)
	TSubobjectPtr<UBoxComponent> Body;
	
};


/** .cpp **/

#include "ComponentTest.h"
#include "MySceneComponent.h"


UMySceneComponent::UMySceneComponent(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	Body = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Body"), true);
	Body->SetBoxExtent(FVector(10, 10, 10));
	Body->AttachTo(this);
	SetHiddenInGame(false, true);

	PrimaryComponentTick.bCanEverTick = true;
}


void UMySceneComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	SetRelativeLocation(RelativeLocation + FVector(0, 0, DeltaTime * 10));
}

Thanks!

Hi ,

I was able to see most of what you described, though I was not able to have the Editor show multiple box components. I have submitted a report to have our developers investigate this further (TTP# 344554). I did have a to briefly talk about this issue with a couple developers this afternoon, and the general consensus at the moment seems to be that the Engine does not always know what to do with components within components.

For now, it would be best to add a BoxComponent to your Blueprint instead of including it inside your SceneComponent.

Great, thanks ! For now I’ll create the components inside of the blueprint.

I didn’t mention this, but I also tried registering the components manually using RegisterComponent() at the end of the constructor. This actually fixed things for the most part, but still drew a copy of the components at the origin (0,0,0).