Array "add" silently failing?

Hello everyone,

I’m working on a system to delete leftover actors when a round ends in my game, but for some reason the “add” node is silently failing!

The way it works is that I add an item to an array of stuff to delete, then later I cycle through that array and delete each member.

There are two possible arrays, so the function is abstracted to take in a list and an object to add to that list.

I also added a debug function to keep track of the array size.

As you can see in the image below, I dump a magazine twice, creating two actors which are sent for GC, but the int count remains at zero, meaning that the array is empty!
image

All methods of calling QueueActorForGC explicitly pass an array.



So, theoretically, there is no scenario where I add something to GC without having an array to add it to. Yet, clearly, somehow it is happening.

The GC blueprint is its own replicated actor, managed by the server.
Here are some examples of how GC objects are passed to the GC manager actor:



What can I do?
I’ve clearly missed something very obvious.

Some suggestions:

  • If the “Add (to array)” node works in the simplest test scenario, then the problem is not the add node.
  • It would be a normal situation if the GC Destroy List is emptied (or were empty) before a new item is added (both items in your test would get index 0).
  • Deleting X on a foreach loop of an array misbehaves. You’d have to remove things end to first item by looping over index (array size - 1 to 0).
  • array pointers are only valid until an item is added or removed from an array.

Seeing nothing obvious on the screenshots currently.

I wonder though, are you trying to implement garbage collector functionality besides the GC that is already working in the background on every UObject?

1 Like

Hello Roy! Thank you for replying, and apologies for taking a bit to get back to you, I was going through your list and performing tests.

For some reason, if I bypas this:

Like this:

image

It all magically works. It seems to be an issue with the custom events. But I’m not sure what the issue is exactly.

I wonder though, are you trying to implement garbage collector functionality besides the GC that is already working in the background on every UObject?

I’m unaware of what GC you are referring to in this case. I assume you mean actual GC like invalid pointers, garbage variables, and anything left over in memory over the course of C++ code running.
Mine is just to deal with deleting and re-setting objects between the rounds of a game.

That… would mean the blueprint system itself is basically dead unless I’m missing something.

Have you used breakpoints before? you can walk through the software node by node while it operates, and read past data.

You are using “GC” as your custom implementation context (to deal with deleting and resetting objects), I am referring to the GC which checks for unreferenced UObjects every X seconds and destroys them (nulling pointers etc.). That GC is built into the engine.

1 Like

I have not. I wasn’t aware Unreal supported them for blueprints. I’ll go ahead and learn real quick how to use them and get back to you in a moment.

I have no knowledge or understanding of that system.

You can put breakpoints on nodes with F9. Works similar to VS. you don’t get neat callstacks but similar data.

Unreal Object Handling in Unreal Engine | Unreal Engine 5.5 Documentation | Epic Developer Community

Garbage Collection | Unreal Engine Community Wiki

As a blueprint user you don’t get do deal with it like a c++ user but it’s important to know that it exists.

1 Like

Hey,

As far as I’m aware events cannot pass array by reference (even if they tell you they do). If you convert your event to a function it should work.

I have no idea if this is a bug or expected behaviour, I tend to never use custom event.

1 Like

(post deleted by author)

I literally always convert my events to functions (I mean theoretically they are already functions). Only downside to this is that several nodes (including delays) can not be converted to functions. I however hope not that such bug exists. It can be tested on a separate simplified test (to exclude external code affections.)

On the first screenshots there’s just an object pointer and int copy sent into the print string which don’t get the desired results. Apparently the bypass of that custom node works (as reported by the person starting the thread).

Test things one by one?

I gave it a try, though they are hard to use since they don’t support standalone play mode (which due to some plugins I use, is the only mode in which my game is fully playable, but for something as small as this, I should be able to make it function just barely enough to do a short test).

(Here would go the part where I mentioned my results, but I never got to it due to the part below…)

This is a bit odd since Unreal itself claims that it only supports pass-by-reference for arrays.

However, Unreal gaslights users about its functionality constantly so I’m going to run a test regardless where I assume that this is true.

I made it so that the “local” bool gets passed all the way through, and then the array is picked based on that bool. Theoretically this should avoid needing to pass any arrays.

Oh what the ■■■■ this works.
image

+1

1 Like

I think it is technically passing the array by reference, in the sense that it isn’t making a copy. But it is a const reference, so not something you can modify.

The thing is, I remember that Event Dispatchers (which have the same limitations) would display a clear yellow warning when you try doing this. I don’t know why custom events don’t do the same.

1 Like