Pox
Pox

Reputation: 31

Unreal Engine : Instanced Static Mesh doesn't rotate on instanciation

I'm currently doing real time growing trees, and i'm using an instanced static mesh component for the foliage, since every leaf is unique. When I add an leaf instance to my component, I put a random rotation on it. But for some reason, this rotation is not set, all my leaves have a zerorotator. The scale is set, the transform too, but not the rotation.

Here is the code :

//Instanced static mesh component instanciation, as a component of the tree
foliage = NewObject<UInstancedStaticMeshComponent>(this);
foliage->SetWorldLocation(GetActorLocation());
foliage->RegisterComponent();
foliage->SetStaticMesh(data->leaves[treeType]);
foliage->SetFlags(RF_Transactional);
this->AddInstanceComponent(foliage);

//Adding a instance of foliage
const FTransform leafTrans = FTransform(
FMath::VRandCone(normals[branches[i].segments[j].firstVertice + 2], 2.0f).Rotation(),
vertices[branches[i].segments[j].firstVertice + 2], FVector::ZeroVector);

foliage->AddInstance(leafTrans);

I recently changed the Instanced Static Mesh Component, I beggined to put it on a child actor, and the rotation worked. But I had to remove it for an other issue.

I'm sure it's a small thing I'm missing, but I'm losing too much time searching on the internet, and there is not that much documentation on this subject...

Thanks :)

Upvotes: 1

Views: 2386

Answers (1)

Pox
Pox

Reputation: 31

Ok, the problem was the scale. For some reason, if it is set to zero, it also set the rotation to zero...

Upvotes: 2

Related Questions