I’m having trouble with my game and I am convinced I am doing something silly that I just cannot figure out.
I’m making a hexgrid and inside a HexTile class I have an FVector that represents the center of the hexagon and a TArray of FVectors to represent the six corners of the hexagon. I calculate these correctly and render triangles accordingly:
As you can see on the details to the right under HexRendering, values of the corners and center of the hex are displayed correctly.
However, I am trying to reference these values via a pointer to the HexTile object but the values are always zero or terribly wrong.
Here I am looping through a select few of the hexes because I am attempting to render them as one mesh to cut down on geometry. However, the UE_LOG seen in the code does not output the correct values. This is the output of that log:
LogTemp:Warning: On col: 0 row: 0 ::: CenterX: 0 CenterY: 0 CenterZ: 0
LogTemp:Warning: On col: 0 row: 1 ::: CenterX: 0 CenterY: 0 CenterZ: 0
LogTemp:Warning: On col: 0 row: 2 ::: CenterX: 0 CenterY: 0 CenterZ: 0
LogTemp:Warning: On col: 0 row: 3 ::: CenterX: 0 CenterY: 0 CenterZ: 0
LogTemp:Warning: On col: 1 row: 0 ::: CenterX: 0 CenterY: 0 CenterZ: 0
LogTemp:Warning: On col: 1 row: 1 ::: CenterX: 0 CenterY: 0 CenterZ: 0
LogTemp:Warning: On col: 1 row: 2 ::: CenterX: 0 CenterY: 0 CenterZ: 0
…and so on
I have no idea why this is. Hopefully someone can help!
Hi T_Reg - for a little more context, what is “HexMap”'s type? Is it a TMap type? Also, where and how is that structure filled in?
It is a TArray where FMapCol is a struct that holds a TArray<*AHexTile>
I’m new to unreal and didn’t see that TMap type… perhaps that would have been better.
Also, after five seconds a Generate() function is called in MapGenerator that fills these arrays and calls a function in the HexTile that takes a center location and calculates the corners from that. This is the most relevant loop in that function:
Have you tried checking if a)
col are in range of their arrays and if b)
current is NULL? I just wonder about the meaning of
x * tilesPerXSubSec and similar and if they result in valid indices.
Yes, they result in valid indices. If they didn’t I think there would be a crash? Anyway, it gives indices in the correct range and in the correct pattern that I want.
I outputted (current == nullptr) and it returned false. I suppose that is the correct way to check that.
There’s something else peculiar I forgot to mention, however. I am able to correctly output something from the current HexTile. I can output a member variable called xSubSection which corresponds to the x coordinate of the subsection the tile is a part of. This gives me the correct values. It’s only when trying to output and access a FVector that this problem occurs.
Okay, since your current HexTile is valid and the values are properly shown in the editor, perhaps your log is just wrong? I’ve noticed that you use %d in your TEXT macro, but members of FVector are float, so I would use %f. Also, you said something about a 5 sec delay before your tiles are placed. Is your log printing after that init for certain?
Well that’s embarrassing… that was it. I thought %d would be correct because I thought it stood for decimal number but it’s an integer. When I replace with %f it works fine.