[C++] Object hierarchy in scene

Hi,

I have two C++ classes that are both AActors with 2D sprites added in blueprint classes. This two classes both derive from AActor.

The first class is the “parent” class that will be the root of my object, this class will spawn the second one and attach it to itself. The main objective of doing this is to give the “child” objects a relative position from the root of the object and that they will rotate with it.

Example object:

 - myFloverRoot
     -  petalo 1
     -  petalo 2
     -  .... petalo n

This is a piece of my code but I can’t really understand a behaviour of some lines so I can’t get to a solution, because the api reference pages are not that good.

void AFlowerGenerator::GenerateFlower()
{
	UE_LOG(LogTemp, Log, TEXT("Generating the flower"));
	GEngine->AddOnScreenDebugMessage(0, 2, FColor::Green, TEXT("Generating the flower!"));

	auto petalo = GetWorld()->SpawnActor<APetalo>(petaloBP);

       // The following lines are my not working solution
	if (!isPetaloSizeRemovedFromSpawnPos)
	{
		isPetaloSizeRemovedFromSpawnPos = true;
		PetaloSpawnPos.Z -= petalo->MySize;
		UE_LOG(LogTemp,Error,TEXT("Spawn position: %s"),*PetaloSpawnPos.ToString())
	}

    // ******************************
    // look here
	petalo->SetActorLocation(PetaloSpawnPos); // the fisrt try used SetActorRelativeLocation but the result was basically the same
	petalo->AttachRootComponentToActor(this);
	petalo->SetActorRelativeScale3D(FVector(1, 1, 1));
	petalo->SetActorRelativeRotation(FRotator::ZeroRotator);
     //can you give me a explanation of this last 4 lines because I really can't understand their behaviour

}

This code with a single spawn gives me a result like this:

https://pbs.twimg.com/media/Ci6bSKEXEAEy09L.jpg:large

The correct result should be the flower center with the petal placed on its border.