Coming from unity, I wanted to give UE a try and was playing around with a test project. Basically, what I’m trying to do is to create a tile map, which spawns in tiles according to the randomized world size.
The spawning works, but The function which is supposed to print the coordinates of all tiles in the resulting tilemap array, just prints 0,0 for every created tile.
Additionally, I get these error messages in the log output:
Sorry if this is an obvious problem, as I said, this is my first test project with UE. I suppose it has something to do with the local variable I’m using, but not sure what?
Hey @CondorDrake! So whenever you see pending kill or garbage, it usually means there’s something wrong with your reference or that the object is being garbage collected for some reason or another. So let’s do a bit of debugging to see where the fault point is and then we can restructure to make a fix.
So first things first, whenever I start getting kill errors like this when something definitely shouldn’t be in garbage collection, I start validating things to make sure we don’t error out. so we can see the error comes in the other function PrintTileCoordinates. So let’s disable that and run everything to make sure that’s the only fault. If the tiles spawn at their correct locations, and no errors are printed, great! Hook PrintTileCoordinates back up and plop a breakpoint on it’s get for the array and the print string. Then pick through and see if that tilemap array is actually being read or if that’s the reference failing.
thanks, I split the whole thing into smaller functions and added more printStrings and I found out, the array seems to be empty. So the Add in the first screenshot doesn’t seem to add the spawned item into the array. Don’t arrays work with other types than integer, string, bool, etc?
Absolutely! Arrays work for every standard data structure. So in your case actors! Now it looks like it adds to the array when it’s generated. So we’re going to have to do an IsValid check on it, print results, and then pass it into the array and print results to test and see if the spawning is outputting the correct actor, that actor is getting put in the array, and then if it’s then staying in it. If the spawning is happening correctly at the correct locations, the only issue is getting a usable reference to the objects and popping them in the array.
Yeah, that’s what makes me wonder, because the spawning works at the correct locations, so the actors are obviously created correctly. I don’t know what else I could do than to add them into the array the way I do it. Are there any other settings I need to make for the array to work?
I realized the problem with the index-1 since my post yesterday and fixed that already, but the problem still persists. Whenever I try to access an array element, I get the mentioned errors. I’ll give the foreach loop a try, thanks.
I was just about to say, I’ve been trying to replicate the issue more simply on my side, but my arrays just work out, I’m guessing there’s got to be some form of data in the array to begin with, nullptrs will produce the same GC type error but the objects being reference exist and are fine but the references themselves don’t seem to be adding to it like the array.
Okay, I rebuild the whole thing and split it up in multiple functions to make it easier to check where exactly it breaks. And surprisingly, I also get a different error message now. The blueprints now:
The PrintStrings are all written correctly now, except the last one in PrintTileCoordinates which isn’t written at all. To me it seems like the items in the array are somehow lost after I leave CreateTiles and once in PrintTileCoordinates, the Array is empty again.
P.S.: Could it be that I need to initialize the array with the SizeX * SizeY before I add items to it? Like in C# I’d do FloorBP[] myArray = new FloorBP[SizeX*SizeY] - is this needed here too? If so, what would be the “Syntax” in Blueprint to do this?
Okay, it’s fixed now - turned out in the array definition, it already created one element in the editor, which I had to remove in the details window. Finally works as it should now, except for this problem : Texture Flickering
Posted at the same time
Yes, that was exactly the problem. Don’t know what the difference between my implementation now and the first one is, but after all, it’s working now
No. This is handled automatically. The array will expand as needed. If the array is too small and you’re setting an index exceeding array bounds, you may need to do it like this: