Download

Good way to save all Instanced Static Mesh locations?

I am developing this: https://jtrocks55.itch.io/universe-constructor and I have a problem I cannot quite crack yet. Basically, I was using static meshes for all of the blocks. Well that made performance very bad, so I am now using instanced static meshes. What I want to do is save them all, each instance, to load it later. Just saving the game, but that seems quite difficult to do with instanced static meshes. Does anyone have some helpful ideas or anything to point me in the right direction? This is what I have so far:

In the widget BP to save game: SaveGame1.PNG

In the same widget BP to load it (starting the process, the rest of the loading is done after spawning the block, so the block can do the rest by adding components saved previously): SaveGame2.PNG

In the Block BP (after block is spawned by Load, the block will take the variables and make ISM components based off of them): SaveGame3.PNG

So if anyone has some ideas or advice, it would help a lot! Thanks in advance :slight_smile:

The way I do it is each location has a series of values, and depending on those values, it spawns specific meshes. So, if I want to spawn things again, I just run those same values through the system and it puts everything where it belongs.

At the most basic level, you really just need a struct array, where the struct has all the relevant info for a single object. That info would be the transform, which instance to spawn, and so forth. So for each item in the array, it knows what instance to load and where it was located in the world. Then you just foreachloop through the array and put everything where it belongs.

Oh ok, I might need a small amount of guidance, but thank you! I do need to go to bed now though. Tired. Anyway, thanks again.

Yeah I am probably going to need help with this. Not certain what I should do here. I am not very knowledgeable of structs.

Think of structs as an array of arrays (that can be of different types). But a way to keep that data “together”, it’s basically exactly what you need for this.

You’re basically going to do the exact same thing you’re doing now, except you’re going to put it into the struct, or break the struct and get the data to utilize. It’s like 1 or 2 extra nodes, it’s probably a lot easier than you’re thinking.

To start just make a struct that has all the arrays you need - mesh transform etc - then instead of getting the data from the save, get the struct from the save, break the struct, then get all your arrays and feed them into whatever is necessary. Same with saving - save the struct instead of individual variables.

Ok, that helps a lot. But here is another problem, if all of the struct variables are actually arrays, how would I for instance “Get Instance Transform” because that returns a single transform, and not an array of transforms:

struct.PNG

Do you think you could send me a pic of an example for me to work off of? I learn very easily visually.

Update: Still not working out. If someone could send a pic of how you save arrays with a structure, that would be great :). I just don’t understand how I would save instance transforms if they are not arrays, but the transform variable in the struct is an array.

Instead of putting arrays in your struct, what you want to do is put single, normal variables in it. Then, you take your struct variable and make an array out of that.

So in your array, each index has a struct containing the transform and all other pertinent info for each individual object. So index 0 is object 0, index 1 object 1, and so on.

Ok, that makes sense, but I am still having trouble. Is this anywhere near close to what it should be?:

Save part:
Struct1.PNG

Load part:
struct2.PNG

When you add it to the struct it looks right, but it is hard to say with the rest as I don’t know the setup.

Print string your struct members as you respawn to ensure they actually have info in them. If they don’t, then print it as you add it to ensure the info is being pulled properly.

You might want to cut out the save portion for now so you can ensure the basic system works. Store the instance spawn info as you spawn it, then destroy it all, and try respawning it immediately. Once that is seamless you can just move the info into the save object and get that working later.

Hey, I got it working (as well as after closing and re-opening, all different meshes and materials save)! Thanks a ton. Your advice really helped. As well as yours Pinworm. So thanks!