Hello, I’m working on a Game where you can basically attach Blocks togther. I attach them using the Attach Actor to Component node, without using Sockets. I want to be able to save entire Constructions to a Savegame and be able to load it, too. The saving of normal Variables seems pretty easy, since you mostly have to just get and then set a Variable, but that would not work for attached Actors, or would it? Could i get the attached Actor and just save it as an Actor reference Variable? But then i would need to reattach it when i load the Game, right? So what would be the best way to save a whole Construction? Also the Constructions are linear, so each Actor has only one Child Actor, if that matters. Also I’m working with Blueprints and I’m not really good at C++. All help is very appreciated. Thank you very much.
The solution to this would vary a lot depending on how you are doing the building part. But have a look at the below and see if it would work for what you’re wanting to do.
This assumes you have some sort of Block class that you are spawning and attaching to placed blocks.
- In your Block class add two Int variables, both editable and exposed on spawn. Index, and AttachedTo.
- When you spawn a block, give each block a unique index. And if it’s attached to another block, also set the AttachedTo variable to the index of the parent block. If the block is not attached to another block, then set AttachedTo to -1 (Maybe this is not relevant to your setup). Something like the below, modified to fit what you have currently:
-
Create a new struct, S_Blocks. Add 3 variables, a vector, location, and two ints Index, and AttachedTo.
-
In your save game blueprint, add an S_Blocks variable and make it an array.
-
In your save function, do this:
- And then your Load function:
Again, might not work for you, but could be a starting point.
Thank you very much. I will try it, but I am very confident that it should work. Since the Blocks have physics enabled, would the loading just ignore it and attach them while they are at their right position, or would they be able to ‘fall’ down to another location, before the Block can be attached? This wouldn’t be a Problem for some Blocks, but in my case it could be a couple hundred Blocks being loaded, so the time interval could be quite high. Enough to let them fall some distance. Also, I am not sure what causes this, but the Blocks can’t be attached to another Block if they have a Block attached to them. In that case they will just drop the Block it is attached to and attach to the other one, so is there a way to order it? And it might take me quite some time to get it set up. Maybe two days, more or less. Then i can tell if it works. Thank you again very much.
I maybe just found a way to order it. Could i let the loading be ordered by a Variable that i can Assign during the Attachment Process? If so, how? Is there a way to order a For Each Loop?
Edit:
I think that i could do it by using the insert node to order the Local Blocks Variable, right? Also sorry for all the unrelated questions.
The index and attached to ints are what orders it. So when you spawn a block, you have to give it a unique index, and when you attach it, you also store the index of the block it is attached to. That is happening in the above graphs.
It should work for physics enabled objects, but you should probably add a WorldRotation rotator to your struct too, so that you can save and load that.
Sorry, i forgot to mention, that you can also detach the Blocks, so by detaching a Block after already having build another Construction or just attaching 2 Blocks together the Blocks would be attached differently, or not? For example: I’ll use this to represent attachment < and this for detaching >. 0<1<2<3<4<5, if i now start a ne construction like this 6<7<8<9 and detach 5 from 4 and attach it to 9, it would be like this 1<2<3<4 ; 6<7<8<9<5 meaning it would attach 1-4 right, but then attach 5 to 9, then attach 6-8 just fine, but attach 9 to 8, which would break the attachment to 5. I don’t know why it deataches a Block if the Parent gets attached, but it does it for some reason. If that wasn’t the case it would just work fine. Thank you again very much for your help. I tried to figure out how i could save it for quite some time and it gave me some pretty bad headaches, so thank you for helping.
I think this should still work, so long as when you attach a block, you update the int which specifies what block its now attached to. Since a block can only ever be attached to one block that should work fine. I think what I have above would be a simple method to start with, after you have tried that and see what problems it has it will be easier to decide what the next steps should be and what tweaks it needs.
I’m still trying to setup the system, but i noticed, that this error causing Blocks to detach if their Parent gets attached actually isn’t there for quite some time anymore. I just thought it was stll there, even though i actually did it some times, without that happening and i just didn’t notice. I think it might take still some hours until I implemented it correctly. I hope it works then:D. Thanks you very much.
Edit: Also, how did you add the Index pin to the SpawnActor? And how did you create a Cast to without Exec pins?
To add the Index, add a new Int variable to your cube, call it Index. Click the Eye icon to make it editable, then in the details of that variable you will see a checkbox, Expose On Spawn. Checking this will add the variable to the SpawnActor node.
To get a pure cast, just right click the cast and choose “Convert to Pure cast”
How would this work with an class array of actors? Multiple different classes of actors in the array
nvm I got it