x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Pointer reference to FVector does not yeild correct values

Hello,

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:

alt text

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.

alt text

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!

Thanks!

Product Version: UE 4.15
Tags:
hexgrid visual.png (688.2 kB)
code.png (15.7 kB)
more ▼

asked Apr 24 '17 at 03:44 AM in C++ Programming

avatar image

T_Reg
41 1 2 8

avatar image scyfris Apr 24 '17 at 03:56 AM

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?

avatar image T_Reg Apr 24 '17 at 04:07 AM

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:

alt text

populate.png (47.0 kB)
avatar image Benergy Apr 24 '17 at 07:54 AM

Have you tried checking if a) row and 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.

avatar image T_Reg Apr 24 '17 at 02:48 PM

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.

avatar image Benergy Apr 24 '17 at 04:48 PM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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. Thanks!

more ▼

answered Apr 24 '17 at 06:19 PM

avatar image

T_Reg
41 1 2 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question