Saving and loading Instanced Static mesh components from an Foliage Actor

Hi all. most survival games have that you harvest trees etc and and that on a world reload the instances are saved , So trees you cut down are still cut and not present in the world.

But I have seen little to no explanation or documentation on this subject.

I have a project where I have a mining gun that can clear rocks and other foliage types as I go about the level.

Now I have made a struct with the instanced static mesh and an index array to later remove the instances on load of level.

I understand that saving Refs to objects is not possible in BP’s right? version 5.3, so when my gun hits a rock and removes that instance, how can I save this so it can be removed again on load level?

I know how to remove it etc , just the part where i need to reference it I am stuck at.

My array for my structs are just full of memory pointers the instance.

please any help here.

You already know how to refer to each individual instance. You also need to use the save game, to remember ( or store ) which instance indexes have been placed or destroyed.

When you restart the game, you can use a BP to read the save game, and re-do the work automatically that the player did during the last run.

But my reference’s are loading blank. so i’m getting not valid returns.
I was under the impression you cannot save object references to a save game object?

That’s right, saving references is not a good idea. You can save their indexes :slight_smile:

Ok so this where I am stuck. there are multiple instanced foliage actors on the map.
I have my Index of the rock destroyed within that Actor.
What Foliage actor does this apply to without a reference to that actor?

Unless all foliage instance actors are Classed as one to the engine?

1 Like

I don’t know what your workflow is, but for me, yes, foliage is one big blob actor :slight_smile:

So I am getting my line trace info, storing the hit components index and object ref. adding to an array that is stored in a world state BP that calls on these REF’s at begin play to remove the instances stored.

obviously this is wrong as the remove instance node wants to know what ISMC to remove. and the stored REF isn’t saving.

So what is the way to do this correctly? no real info on this subject.

I’m sorry, I am not understanding your replies. I have a save system already setup. The remove instance Node wanting a REF is my issue.

The remove instance node probably takes the reference to the whole foliage actor as the reference, I assume.

I don’t understand why you seem to have separate objects in the outliner.

Take a look at this

and

Well. every time I use the foliage paint tool on a new part of the map I am decorating, it generates a new Foliage instanced actor.

Anyway, i’ll look at the Videos, thank you for your time

1 Like

Hi, are you using WorldPartition? That creates multiple Foliage Volumes, for each tile.

You can find which volume that your instances are in by finding the volume from the instance world position.

2 Likes

Hi, Yes I am using WP. that would explain the separate Foliage Actors.
I’ll certainly look into this thank you.

2 Likes