Strange instanced actors behavior

In Unreal Engine 4.27, I have a blueprint called “1kCrate”, it’s a paperflipbook actor and I have blueprinted it to change flip book on collision event, add points to the player score, have a delay, then to hide the actor and add an instance editable string variable that’s different for each instance to an array to save and load to determine which actors to hide again. This works perfect, for many of the actors, but for some reason, some of the actors won’t get added to the array.

Even stranger, if I have the blueprint for 1kCrate open while playing in the editor, I noticed that all the crates that aren’t being added to the array also don’t execute any of the nodes in the blueprint editor, but the ones that do get added, are visibly firing all of the nodes. I’ve confirmed that they are in fact the same blueprint for each, they were all duplicates and they are still all identical. For example, crates 1-6 don’t fire in the blueprint window, but crate 7 does, and is also added to the array.

All crates 1-7 behave correctly in game, changing flip book, adding score, and becoming hidden. But only crate 7 will be visibly executing, and also become added to the array. The same instances behave the same way each time. I could try duplicating the instances that work properly and replace the non functional ones, but I would have to check about 1,000 crates for ones that work right and ones that don’t. They are identical in every way, except for this specific behavior.

Is there an obvious solution or cause to this?

I don’t see anything obvious, but my guts tell me that maybe, you create an instance and since it’s not used anywhere, it gets cleaned up by the garbage collector. But I really don’t know.

When you say : “won’t get added to the array”, could you please show us how you create the instance and add it to the array ?

It sounds like a code problem :slight_smile:

The reason you only see one execute is this

In the BP, you have to specify which one you want to watch.

Here’s a screenshot of the blueprint, minus the save/load functions. I noticed that if I don’t specify a blueprint to watch with the debug filter, it predictably shows the blueprint execute with the instances that are added to the array and doesn’t visibly execute anything for the ones that don’t, although the rest of the blueprint executes in game. If I do select a specific crate that doesn’t get added to the array on the debug filter though, it does show it execute, even when it isn’t being added to the array. Strangely, when I opened the editor today, a new instance is being added to the array (and visibly executing when nothing is selected in the debug filter), while the others that didn’t work before are still not working.

I also tested more crates, for example crates 150-156 won’t be added to the array, but crate 157 will. 158-164 won’t.

I had created everything up to “set actor hidden in game” and duplicated the blueprints by holding option and dragging, and did this for all crates in the game. After placing them all, I added the instance editable “crateID” to the blueprint. Then I added the ending part of the blueprint to add it to the array, and created the save and load function, and went through them one by one in the world outliner to give them all a unique crateID. It seems that random instances do this properly and others won’t, although they have been consistently the same ones that work and same ones that don’t, with the exception of one instance working today that didn’t yesterday. They are all identical except for their CrateID, so this is rather perplexing :o haha

Any ideas?

That variable ‘crate array 1k’, it only exists inside each blueprint, right? Is this the crate or player BP?

This is the crate BP, and crate array 1k is an array variable in that BP. In the Save Game function, I cast to a save game object and set a variable called “crate array 1k save” to the array from the crate BP.

So far, I’ve identified that crates with these crateID’s will properly save and load: crateID1, crateID7, crateID105, crateID107, crateID157

Ok, then. But you’re adding to an array that only exists in each crate. You need the array outside the crates, perhaps in the game instance or save game, to collect the array.

Here’s screenshots of the rest of the crate blueprint, the functions for save crates and load crates, and to show how I’m checking the array on event begin play to hide the actors



I was wanting to simplify the loading and hiding process so there wouldn’t have to be two “for each loops”, so this would already help with that. Shouldn’t they still all be working properly with this current setup though, seeing that some are working right consistently and others aren’t? Does the screenshots give any indication of what the problem could be?

I think you’re loading the crate array in each crate at begin play?

Then anything that happens up until this crate saves itself will get binned when you walk into this crate, because it writes a mostly empty array into the save game.

You need to get the array, right at the moment you’re going to update, and then save immediately.

To be clear, the crates get a COPY of the array when they read from the save game, not access to it.

99.99% sure that’s the problem :slight_smile:

2 Likes

Here’s the end of the blueprint for the crates, where the actor is hidden, then it gets the “crate array 1k” and adds it’s crate ID to that array, then executes the “save crates” function.

In the save crates function, it gets the crate’s “crate array 1k” variable that now has another crateID added to it, and sets the “save crates” save object’s “crate 1k array save” to be the same, and saves to slot.

Then when the game begins the next time you play it, since the crate array 1k variable will be empty again, right after event begin play it executes the load crates function, which gets the saved “crate array 1k save” variable from the save object and applies it to the crate’s crate array 1k, to restore the array to where it was the last time the game was played.

It works right for several crates each time, but never works right for others. I sorta understand what you’re saying, but I need help with how it translates to modifying the blueprint to work right. What do I need to change exactly from where it’s at now?

Appreciate the help very much!



This is the problem area

Let’s say, it’s a fresh game, the array is empty, you leave this crate till last. You go and pick up all the other crates, and then you come back to this one.

It then writes it’s empty array into the save game. :slight_smile:

When you want to save, do this

  1. Read the array from the save game
  2. Update it
  3. Write it back
  4. BANG

That’s it, as quick as you can :slight_smile:

Wait, I think you are doing that - it’s getting late here. I will think it over…

No, I’m right :slight_smile: It’s updating it’s array, then reading a fresh array from the save game ( which overwrites it’s own array ), and then writing it back.

1 Like

This makes sense and helps to simplify it, here’s what I have so far although it isn’t saving or loading anything yet. For the “cast to SaveCrates” node I have the object connected to a save game variable that’s in the crate blueprint called “Save Ref” which is what a tutorial said should be connected to it within the “save game” function, but is that right and does it make sense in the event graph too, such as after event begin play when I’m pulling from the array that’s in the savecrates object?




It seems that something I’ve changed caused it to not create a save file anymore, perhaps once that’s fixed it’ll be working properly now?

Solved! Here’s the end result, all crates are now saving and loading properly. Thank you so much for the help!




1 Like

:+1: :sunglasses: