Object Outline Issues

Hi everyone. First post here.
I’ve followed and slightly altered a tutorial I found on youtube (Unreal Engine 4 Tutorial - Basic Object Outline (Interaction) - YouTube).
The modification was to make the object outline respond to a Line Trace instead of a Distance Node.

However, I’ve seem to run into a bug where the outline works when putting the cursor onto the object, but in some cases, when it is removed from the object, the outline stays put.
It’s infrequent when it happens, and I can’t seem to make sense of it, so I’m guessing I’m not “checking” the line trace properly?

I’m slightly noobish in scripting so I’m sorry if I’m not describing this correctly.

My First Person Character Blueprint:

The blueprint:

The result:

http://ackehallgren.com/ue4/bpgif.gif

SAVE the actor you traced into a variable and make a branch where you check if the NEW traced actor is EQUAL the OLD/SAVED traced actor.

If NOT, then tell the OLD/SAVED traced actor to remove the outline and the NEW traced actor to show the outline.
Also save the NEW traced actor to the variable and override the OLD/SAVED traced actor.
If YES, do nothing.

And if you are not hitting anything, also tell the OLD/SAVED traced actor to remove the outline and set the variable to nothing.

ALSO make sure to use “IsValid” on the variable you saved the traced actor in, so you won’t call stuff on it without having a reference to it.

EDIT: You might also want to check if the traced actor has the interface even implemented. Because if not, it’s the same procedure as if you would hit nothing.

From what I can see happening would be that by the time the frame checks the trace it has already lost reference to the actor and would try and call the even on whichever actor is currently being traced. Which leads to a bit of a pickle.

What will help fix this issue would be to save a reference to hit actor when it is a valid “MouseOver” type object. If the traced actor (next frame, next trace) is not the same as the one referenced, send your “On Hover False” event to the referenced actor, then clear the actor reference, and wait for the next available valid actor to set it again. If it is the same you can also save some overhead by not calling the event again as mouse over would already be enabled, and it would await the mouse to be moved off the actor.

Hope this helps! :slight_smile:

Thank you both for the speedy help!
So I’ve tried to do what you guys said, but I think I’m not quite grasping it. I cross referenced another project that I found online, but now the outline doesn’t show up at all.
Again, really sorry for not understanding, I’m still new to this kind of scripting.

This is what I have now. OutlineHit is the variable.
6e2458e1a88b940f1a1d981e72a47bb9cc8b733e.jpeg

First of all, the “CastToActor” is not needed. HitActor is already of type actor. Since you are using Interfaces, you don’t need to cast.
Actors that don’t have this Interface won’t do stuff when calling it on them, since there is no implementation for it on them.

I will write it down again:

  1. When you hit something, so the ReturnValue is TRUE, you check if the “OutlineHit” Reference is Valid.
    Means, you check if you already saved something in it or if the Variable is empty.
    In other words, you check if you just traced something with the trace that happened before or if not.

1.1. IF the “OutlineHit” Reference is Valid, it means you JUST traced an Actor before, that you probably saved into this variable, and you need to check if you are now
tracing the same actor again or a new one. So you compare the variable with the HitActor.

1.1.1. If they are EQUAL (Branch is true), you’re tracing the same actor again, so nothing to do.

1.1.2. If they are NOT EQUAL, you’re tracing a NEW actor, so you remove the outline from the one that is saved in the variable,
add the outline to the new one (HitActor) and save HitActor into the “OutlineHit” Reference.

1.2. IF the “OutlineHit” Reference is NOT Valid, it means you traced nothing before, so you don’t need to think about the Variable and just deal with adding the Outline to the HitActor.
After that, you can save this HitActor to the “OutlineHit” Reference.

  1. When you are not hitting stuff. You check if the “OutlineHit” Reference is Valid.

2.1 If YES, you remove the outline from the “OutlineHit” Reference and set the Reference to nothing.

2.2 If NOT, you don’t do stuff.

Hopefully that is better explained.

It also might help you to watch this Stream to get better knowledge of casting, reference, interfaces etc.

Ahh I think I see the problem. The ‘Cast to Actor’ node would likely fail if the actor type is specifically an ‘Actor’ class. In this case the cast will specifically need to to be the ‘Light’ asset you have in your scene, but because want to have possibly hundreds of actors which you will need to cast to, it is likely that it wouldn’t be the most efficient way of doing things.

Replace the ‘Cast to Actor’ node with another branch. What you can do is check to see if the hit actor has the interface you are going to try and call (as eXi had mentioned), which can be done with a ‘Does implement interface’ node. If true, it can set and call the the message, if not then it will just run the hover false message (if the actor is set).

Most of what you had done was correct, just little changes here and there to getting things working properly. :slight_smile:

The Actor cast won’t fail. In fact it will work all time. You can’t place anything higher up the chain than Actors. So everything in your Scene has Actor as parent.
It CAN’T fail. Just remove it, it’s not needed.

Hoho! My god! It works! Thank you so much!
There seems to be almost an opposite bug now, where sometimes, if I’m fast, it won’t re-light up.
Anyway, regardless, it is so much better now.

This is how the script ended up, I’m sure there’s still room for improvement but I think I finally understood what I did…ish. Thanks a bunch!

**Update: **I removed the Hit Actor connection when Saving the actor in top right, and that seems to have done the trick. This is awesome. Thank you again!