Changing the BaseID of a foliage instance?

Is this possible via a Blutility perhaps?

I have need to transfer a ton of foliage from one terrain to another, so I need to figure out how to “attach” the instances to the new terrain object.

Unfortunately that’s not so easy. You could just copy it to your new level + then manually adjust the position of the meshes so that it fits to the terrain: https://answers.unrealengine/questions/138459/how-to-copy-foliage.html :slight_smile:

I have actually found a very easy way to do this, but I haven’t had time to make a writeup about it. :smiley:

Really? Would be cool if you could post it into this thread so that we know how it works :smiley:

Well, after quite a bit of digging through the foliage system, I’ve found that AInstancedFoliageActor has a function called “MoveInstancesToNewComponent” which will take all the foliage attached to component A and attach it to component B. Thus, first I’ve created a small utility function in my BlueprintFunctionLibrary, like this:


void UMyunctionLibrary::UpdateFoliageBaseComponent(AInstancedFoliageActor* IFA, UPrimitiveComponent* OldComp, UPrimitiveComponent* NewComp)
{
	IFA->MoveInstancesToNewComponent(OldComp, NewComp);
}

After that I’ve gone ahead and made a Blueprint that would take care of the heavy lifting (Possible to do it with Blutilities too). This is where it got tricky. First I had to figure out which component on the landscape foliage attaches to. After quite a bit more digging it turned out to be something called Landscape Heightfield Collision Component. Each of your landscape components has one of these. Having that only one thing remained - since my two landscapes don’t have the same number of components, I had to figure out which component to map to which. I made a small “find closest component to this component” algorithm to do that mapping and it called the above utility function on them. Here are images of the Blueprint:

e98f155221069a5859f7e252d7af0149ea1745f9.jpeg

In the second screenshot, ClosestDistance default value is -1.

(Sorry for the spaghetti, was trying to make everything fit in).

The transfer foliage custom event is marked as “call in editor”. Now just drop this actor into your level, select the two landscapes as his two variables and run the TransferFoliage event from the Blutility drop down.

Nice, thx for posting! :smiley:

No problem! I’m sure I’m not the only one who needed this. =D

Hello Damir and thanks for this piece of code and explanations !

As I tried to implement your solution in my game, I get some compiler errors… To call “MoveInstancesToNewComponent”, I have to include InstancedFoliageActor.h (“Runtime/Foliage/Public/InstancedFoliageActor.h”), but my compiler is not happy and tells me that InstancedFoliageActor.generated.h cannot be opened :confused:
Have you got this problem while working on this and if yes, how did you fix it ?

Thanks a lot for reading

This move foliage to new component function would be great to have as an official blueprint node…