Line Trace HitActor Value Behaving Weird?

I’m working on a block-based building system, and I’m currently working on rendering a sort of “preview block”. This block will act as a preview where the currently selected block and its rotation will be built.

However, I’m having some issues. I’m using Class Is Child Of to rule out if the Line Trace is hitting anything that is not a Block (Box, Prism, Tetra and Inner Corner - all separate BPs).

Currently I’m trying to make it so that whenever the player looks at something that is not a block, it will reset the Preview Block to 0, 0, 0*(I prefer to do this than to just destroy it, less messy)*.


I was printing a message before, instead of trying to set its location. And it output a message all the time until I looked at one of the block types - after that, it stopped working, it would never trigger again. Whether I re-toggle build mode or not.

Any ideas as to what might be causing this? Am I doing something wrong?

The snapping itself works fine, but it gets stuck at its last location.

Edit:

I recorded a short clip showcasing the issue, I forgot to change the OBS settings for recording so the quality is less than potato. Sorry for that…!

Where do you get your “HitResult”? Because the skybox as far as I know does not result true for a trace and on top of that there’s the question if you trace far enough.

In this case it would use the last hit result it actually found. This should default back to your 0,0,0 as well. Small tip here: Hide the block rather than just setting it’s location to 0,0,0 (do both). For debugging right now this works well but you don’t want to see that block later in actual gameplay :wink:

Second tip: Create a parent class for all your blocks and only check for that one here. If it should behave differently you can do that later on but since it should do the same in this case that will be a far better looking solution and also be cleaner… let alone easier to implement a new block.

Hey thanks for your response,

I do a line trace with every tick and I then store the result in a variable. I get this result whenever I left-click and I check the hit actor to make sure it’s a child of my blocks. This all works well except for the last part where it should set the preview block’s location back to 0, 0, 0.

It loops through all 4 of those and if neither of those are true - it will default to false, and after that it should set the block’s location to 0, 0, 0 but it doesn’t. That part only gets triggered when I remove a block, as demonstrated in the video.

I will play around with the distances and see what I can make out of it.

As for the second tip, I have had plans to migrate this into a BP using instanced meshes at a later stage - but I’d need to do some research on instanced meshes in UE4 before I do so :slight_smile:

I managed to solve this via storing the Return Value of my Line Trace in a boolean variable, as it returned False whenever I was looking at the SkyBox.

Another thing I had to do was to add more Object Types to the linetrace, I currently have WorldDynamic, WorldStatic and Pawn. Since it kept using the oldest HitResult in the variable, and I couldn’t find a way to set it to null - this was the only solution I could figure out.

It is now successfully hidden and working as I would like it to!