I’m trying to figure out how to get world locations of foliage instances that have been painted onto a StaticMeshActor using the foliage brush, but not having much luck.
I’ve created a C++ class derived from AStaticMeshActor. In the editor I can assign it a mesh (for example a plane) and then paint foliage instances on it in the editor. I then want to be able to get an array of all the instance types and locations. Here is what I am trying (this code is in the BeginPlay for the AStaticMeshActor-derived class, which now has the foliage instances painted on it:
The code is finding the InstancedFoliageActor, but maybe I’m misunderstanding what I’m supposed to pass to the ‘GetInstancesForComponent’ function, because it is returning an empty TMap.
Or perhaps there is a different/better way to access the FFoliageInstancePlacementInfo data for all the instances?
The BaseId always seems to be ‘1’ but ComponentHash is just empty, which means the InstanceSet is false so the arrays never get built beyond that.
What’s weird is that MeshInfo.Instances is also empty, even though there are definitely instances that have been placed, and MeshInfo.Component.SortedInstances shows Num=7 (which is the correct number of foliage instances that I have painted in the scene).
Still no closer to figuring out this works and why it’s going wrong though…
I figured out how to get the information I need. The code below will output the mesh name, translation, rotation, and scale for each foliage instance in the scene: