Following code works as a work around.
The code updates placement information of instances.
TMap<UFoliageType*, TArray<const FFoliageInstancePlacementInfo*>> AInstancedFoliageActor::GetInstancesForComponent(UActorComponent* InComponent) { TMap<UFoliageType*, TArray<const FFoliageInstancePlacementInfo*>> Result; const auto BaseId = InstanceBaseCache.GetInstanceBaseId(InComponent); if (BaseId != FFoliageInstanceBaseCache::InvalidBaseId) { #if 0 for (auto& Pair : FoliageInfos) { const FFoliageInfo& Info = *Pair.Value; const auto* InstanceSet = Info.ComponentHash.Find(BaseId); if (InstanceSet) { TArray<const FFoliageInstancePlacementInfo*>& Array = Result.Add(Pair.Key, TArray<const FFoliageInstancePlacementInfo*>()); Array.Empty(InstanceSet->Num()); for (int32 InstanceIndex : *InstanceSet) { const FFoliageInstancePlacementInfo* Instance = &Info.Instances[InstanceIndex]; Array.Add(Instance); } } } #else const auto CurrentBaseInfo = InstanceBaseCache.GetInstanceBaseInfo(BaseId); const auto NewBaseInfo = InstanceBaseCache.UpdateInstanceBaseInfoTransform(InComponent); FMatrix DeltaTransfrom = FTranslationMatrix(-CurrentBaseInfo.CachedLocation) * FInverseRotationMatrix(CurrentBaseInfo.CachedRotation) * FScaleMatrix(NewBaseInfo.CachedDrawScale / CurrentBaseInfo.CachedDrawScale) * FRotationMatrix(NewBaseInfo.CachedRotation) * FTranslationMatrix(NewBaseInfo.CachedLocation); for (auto& Pair : FoliageInfos) { FFoliageInfo& Info = *Pair.Value; const auto* InstanceSet = Info.ComponentHash.Find(BaseId); if (InstanceSet) { TArray<const FFoliageInstancePlacementInfo*>& Array = Result.Add(Pair.Key, TArray<const FFoliageInstancePlacementInfo*>()); Array.Empty(InstanceSet->Num()); for (int32 InstanceIndex : *InstanceSet) { FFoliageInstancePlacementInfo& Instance = Info.Instances[InstanceIndex]; FMatrix NewTransform = FRotationMatrix(Instance.Rotation) * FTranslationMatrix(Instance.Location) * DeltaTransfrom; // Update rotation and position Instance.Location = NewTransform.GetOrigin(); Instance.Rotation = NewTransform.Rotator(); Array.Add(&Instance); } } } #endif } return Result; }
Result:
Foliage instances is placed in wrong location
[Link Removed]
[Link Removed]
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-190262 in the post.
1 |
Component | UE - World Creation - Worldbuilding Tools - Level Instances |
---|---|
Affects Versions | 5.2 |
Target Fix | 5.6 |
Created | Jul 8, 2023 |
---|---|
Updated | Oct 11, 2024 |