Weird actor spawn until scale change - Bug?

Hello, I have an actor blueprint class derived from cpp class. Spawning it manually works as intended but when i try to spawn it via GameModeBase class it spawns incorrectly; toggling actor’s scale fixes it (see video). Calling SetActorScale3D(FVector(x)) fixes it if x != 1 (see spawn function for example).
Any way to fix that? Looks like a bug to me.

Video

Scale numbers are the same (0:22 and 0:31, right-bottom corner)
YouTube Link

Actor desctiption

I expose UStaticMesh references to the editor and set them manually and then assing static meshes to components on construction. Each mesh has socket attached to it.

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "MeshComponent")
		UStaticMeshComponent* ExampleMP;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Mesh")
		UStaticMesh* ExampleM;

AProceduralRoom::AProceduralRoom()
{
	PrimaryActorTick.bCanEverTick = true;

	bOverrideTick = !PrimaryActorTick.bCanEverTick;

	MainFloor = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MainFloorMeshComponent"));
	SetRootComponent(MainFloor);
	RootComponent->SetMobility(EComponentMobility::Stationary);

	FirstLadder = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("FirstLadderMeshComponent"));
	//FirstLadder->SetupAttachment(MainFloor, TEXT("nextSpawnLocation"));
	
	SecondaryFloor = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SecondaryFloorMeshComponent"));
	//SecondaryFloor->SetupAttachment(FirstLadder, TEXT("nextSpawnLocation"));
	
	SecondLadder = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SecondLadderMeshComponent"));
	//SecondLadder->SetupAttachment(SecondaryFloor, TEXT("nextSpawnLocation"));
	
	BorderTrigger = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BorderTriggerMeshComponent"));
	//BorderTrigger->SetupAttachment(SecondaryFloor, TEXT("nextSpawnLocation"));

	GenerationSeed = 0;
	RoomNumber = 0;
}

void AProceduralRoom::OnConstruction(const FTransform& Transform)
{
	Super::OnConstruction(Transform);

	if (GenerationSeed % 13 == 0) {
		MainFloor->SetStaticMesh(LegacyFloor);
	}
	else {
		MainFloor->SetStaticMesh(DefaultFloor);
	}
	MainFloor->SetGenerateOverlapEvents(false);

	FirstLadder->AttachToComponent(MainFloor, FAttachmentTransformRules::SnapToTargetNotIncludingScale, TEXT("nextSpawnLocation"));
	FirstLadder->SetStaticMesh(Ladder);
	FirstLadder->SetGenerateOverlapEvents(false);

	SecondaryFloor->AttachToComponent(FirstLadder, FAttachmentTransformRules::SnapToTargetNotIncludingScale, TEXT("nextSpawnLocation"));
	SecondaryFloor->SetStaticMesh(ConnectionFloor);
	SecondaryFloor->SetGenerateOverlapEvents(false);

	SecondLadder->AttachToComponent(SecondaryFloor, FAttachmentTransformRules::SnapToTargetNotIncludingScale, TEXT("nextSpawnLocation"));
	SecondLadder->SetStaticMesh(Ladder);
	SecondLadder->SetGenerateOverlapEvents(false);

	BorderTrigger->AttachToComponent(SecondaryFloor, FAttachmentTransformRules::SnapToTargetNotIncludingScale, TEXT("nextSpawnLocation"));
	BorderTrigger->SetStaticMesh(EnterLeaveTrigger);
	BorderTrigger->SetHiddenInGame(true);
	//BorderTrigger->SetGenerateOverlapEvents(true);	
}
SpawnFunction
void AMyGameModeBase::AddProceduralRoom(FTransform NewRoomTransform)
{
	UWorld* World = GetWorld();
	if (World) {
		AProceduralRoom* NewRoom = World->SpawnActorDeferred<AProceduralRoom>(ProceduralRoomClass, NewRoomTransform);		
		if (NewRoom) {
			//Just sets some int's
			NewRoom->Initialize(CreatedRoomsMap.Num(), GenerateRoomSeed(CreatedRoomsMap.Num()));
			NewRoom->FinishSpawning(NextRoomSpawnPoint);

			/* Uncomment to 'fix' spawning
			NewRoom->SetActorScale3D(FVector(2));
			NewRoom->SetActorScale3D(FVector(1)); */

			NewRoom->GetBorderTrigger()->OnComponentBeginOverlap.AddDynamic(this, &AMyGameModeBase::OnRoomBorderTriggerBeginOverlap);
			NewRoom->GetBorderTrigger()->OnComponentEndOverlap.AddDynamic(this, &AMyGameModeBase::OnRoomBorderTriggerEndOverlap);
			NextRoomSpawnPoint = NewRoom->GetNextRoomSpawnPointTransform();
		}
	}
}

rotation not correctly?

1 Like

Can you please elaborate? I do not change rotation as RootComponent->SetMobility(EComponentMobility::Stationary) so it should be the same.

BTW I have edited actor constructor a bit.

UPDATE: Others’ components mobility was not inherited from RootComponent (as I thought), manually setting their mobility to Stationary fixed problem.