Unable to Read memory of property on Blueprint still in the game

In my ResourceManager’s BeginPlay() method I populate an array. This array is a private UPROPERTY() in the header file:

private:
	UPROPERTY()
	TArray<ASpawn*> Spawns;

When I debug, this array is successfully populated.

But later when I call another method on the Actor, i.e Shoot(), the array setup in BeginPlay() is now ‘Unable to Read memory’ and throws an access violation exception.

Presumably this means the GC collected the array?

My understanding is that because my ResourceManager is an actor on the map, and it has a UPROPERTY in the header file, I would not expect this array to be collected.

I’m assuming you’re compiling the “DebugGame Editor” configuration. If you’re using the “Development Editor” configuration, you can’t rely on the debugger finding the correct memory.

You say you’re getting an access violation? So your game crashes? That’s not GC. That’s a bug in your code somewhere.

Also, GC won’t trash the array. It’ll just set some elements to null. That’s it.

Thanks for this, that’s correct I’m using the DebugGame Editor.

Could you help me understand what it means when the debugger says ‘Unable to read memory’ because I haven’t come across this before? That’s correct it crashes when it tries to read the array.

There is nothing fancy about the code at all, it simply creates and fills the array in BeginPlay(), and then the array cannot be read when a different method is called later

I can only assume the .h property is not lasting beyond BeginPlay()

What is this ResourceManager derived from? (a subsystem, an actor, a component of UWorld) (mostly to see how difficult it can be to look at in the editor)
Could you maybe expose this to the Editor either through UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess ="true")), or by temporarily making it public, then just look at the array for anything that is null. if this is the case then you need to either trim it, or have something for skipping things that are null.
Are you doing any trim type things to your Array?

how are you reading the array?
are you iterating over it (using a For loop or iterator) ? (this will probably be in the callstack for your crash) if you are manually doing the for loop are you going out of bounds?
what is the code that reads the array, how are things added to or removed from the array? (are you sure that as these Actors are being destroyed that they are being removed from the Array)

can you in a blueprint somewhere put a GetAllActorsOfClass(class = Spawn) spit out the number, and then count how many return true of PendingDestroy then log out the length of your Spawns and see if they match

So I’ve massively simplified it to take arrays/objects out of the equation, and just use an int:

void AResourceManager::BeginPlay()
{
	Super::BeginPlay();
	MyNumber = 555;
}

Then when later read:


FResourceInfo* AResourceManager::Find()
{
	MyNumber = 333;
}

Throws when reading MyNumber:

Exception thrown: write access violation.
this was nullptr.

MyNumber is a UPROPERTY in the header file. When it says ‘this’, does it mean MyNumber, or the instance of the class it’s executing itself?

Ignore me I have a Blueprint referencing a C++ class instead of a blueprint… that’s what’s messing thing saround

‘this’ is the instance. Members cannot be null unless they are pointers (or smart pointers). So your AResourceManager instance got deleted. Where is the property that holds the reference to your resource manager?