Accessing TMap with dedicated Keys from for loop

UPROPERTY()
TMap<int64, TArray<struct SolarSystemDefinition>>* collisionmap;

i have read about this UPROPERTY() thing on TMap but i wondering why it would be randomly garbaged collected… anyway

i have this code

int64 indices[9]{}; ←- everything is ok
GenerateIndices(indices, xi, yi, zi, 1); ←- everything is ok
TArray* collisionarrays[9]{}; ←- everything is ok, i guess
collisionarrays[0] = collisionmap->Find(indices[0]); ←- cant access the TMap anymore
collisionarrays[1] = collisionmap->Find(indices[1]);
collisionarrays[2] = collisionmap->Find(indices[2]);
collisionarrays[3] = collisionmap->Find(indices[3]);
collisionarrays[4] = collisionmap->Find(indices[4]);
collisionarrays[5] = collisionmap->Find(indices[5]);
collisionarrays[5] = collisionmap->Find(indices[5]);
collisionarrays[6] = collisionmap->Find(indices[6]);
collisionarrays[7] = collisionmap->Find(indices[7]);
collisionarrays[8] = collisionmap->Find(indices[8]);

as u can see there is no for loop atm couse i changed it and try this approch

but this isnt working too…

ok maybe one of the c++ experts is able to explain me this:

i moved

TArray* collisionarrays[9]{};

and

int64 indices[9]{};

to the class definition and its working…

so my c++ skill are really underground or im missing something

This shouldn’t have anything to do with garbage collection, that only happens between frames and should only affect things such as TObjectPtr. You shouldn’t need this TMap to be a UPROPERTY().
Could you post the code that you use to generate the collisionmap (which seems to be GenerateIndices)? That might help clarify what’s happening. It might be something like not passing in the indices by reference, or something else of the sort?
Other things to try, assuming you want to do it your original way: Assuming you’re using Visual Studio, putting a breakpoint on that first line where you attempt to access collisionmap and seeing what the values of collisionmap and indices are could be illuminating. Use UE_DISABLE_OPTIMIZATION and UE_ENABLE_OPTIMIZATIONbefore and after your code respectively if the values are optimized away for some reason.

static void GenerateIndices(int64* array, const short& xi, const short& yi, const short& zi, const int& i)
{

    int32 count = 0;
    for (int x = -i; x <= i; x++)
    {
	    for (int y = -i; y <= i; y++)
	    {
		    for (int z = -i; z <= i; z++)
		    {
			    *array = getindex(xi - x, yi - y, zi - z);
			    array++;
		    }
	    }
    }
}
static int64 getindex(const uint16& xi, const uint16& yi, const uint16& zi)
{
    int64 index = 0;
    index |= xi;
    index = index << 16;
    index |= yi;
    index = index << 16;
    index |= zi;

    return index;
}