LineTrace Branch, Tag Check Error

I’m trying to set up a system that changes the colour of the crosshair based on whether the player is aiming at an enemy or not using tags (“enemy”=red, none=white).

The code works fine when the line trace hits an Actor tagged “Enemy” but throws an error when it hits anything else without a tag. This is the error:

Blueprint Runtime Error: “Accessed None trying to read property CallFunc_BreakHitResult_HitActor”. Blueprint: PlayerCharacter Function: Execute Ubergraph Player Character Graph: EventGraph Node: Branch

It points to the last Branch node which checks if the Actor has the “Enemy” tag. I can’t figure out why it’s causing a problem as the branch should be False if there’s no tag, right?

Any help would be great, thanks!

Use blocking hit to check it something was found:

image

Thanks for the reply! I’ve had a quick play around with that Bool but not having any luck, I’m not sure exactly where you’re suggesting to use it.

At the moment, you making the check here

image

Try doing the check by using the ‘blocking hit’ pin instead.

Ah gotcha. Unfortunately that still produces the same problem.

Can you show what you have now?

Sure:

And when you click on the error, it takes you to this one?

Ah wait, you’re calling this on tick?

If so, then remove this

I’m calling the “CheckIfEnemy” event once on the “BeginPlay” event, and then it calls the start again every x-seconds (sorry misleading comment perhaps).

Also: that delay node would usually have a much smaller delay but the constant messages in the log where driving me crazy

And yes, that’s the offending branch.

I don’t get it. I have virtually the same thing:

and it works fine ( on tick! ).

I’m starting to suspect that delay actually. I think you might be getting restarts from executions where there was no actor jumbled up with good ones.

Can you try it on tick?

I’ve tried OnTick and still get the same error… just a lot more often. I also tried unhooking the delay at the end and still get the error but only once (obviously).

I’m pulling my hair out a bit because I can’t see anything wrong with that branch, it’s like it’s handling the “false” condition strangely or doesn’t know what to do with an object that has no tags…

Well, you can put an isvalid down there, but it still doesn’t make sense…

Any chance you’re creating and destroying actors at a great rate? Could the actor be culled between the line trace and the tag check?

I’ve even given up on this idea while typing it actually, because that code wouldn’t be split over a frame…

Ok, I’ve copied the code, and have no problem. The only bit I don’t have is

image

Is that variable set?

So it took me reverting to an older build which worked and building up again to figure this out:

There’s a piece of geometry I’m using for testing which is in front of the player when they spawn in. The error only flags up if the raycast hits a piece of geometry. Converted it to a static mesh and the errors go away!

So I’m not sure exactly why still but geometry doesn’t do well with tags and/or linetraces I guess.

‘Piece of geometry’… hmmm. It’s not an actor, then. Which is what the line trace was assuming :slight_smile:

Apparently, good to know for next time! Thanks for the help all the same :smiley:

1 Like