Show Object Interaction

Hello, looked around the answer hub here and I can’t seem to grasp much, still relatively new to Unreal.

What I’d like to be able to do is either highlight an object showing that the player can interact with it.

----OR----

Show a cursor (custom cursor like a hand) that shows the player the object can be interacted with.

Either two of these methods would be great to be taught how to do. I just don’t know where to start, sorry! so I’m hoping someone here is able to help me :slight_smile:

The project I’m making from a first person point of view if that helps.

Having exactly the same problem as this, currently building a first person horror game using blueprints and trying to implement a similar system to Amnesia where you can see different cursor icons according to different contexts. Anybody have a solution preferably using blueprints?

Nobody able to help with this? would appreciate even just a little kickstart :slight_smile:

The PlayerController class has a CurrentMouseCursor property that you can use to change the mouse cursor. Maybe that will work for you?

Blueprint

86400-setcursor.jpg

C++

CurrentMouseCursor = EMouseCursor::Hand;

If you want to draw an outline around an actor you can do it using a post process volume and custom depth rendering. It’s more involved but here is good tutorial with a shader material that you can download and use. Tutorial – Creating outline effect around objects | Unreal Engine 4 blog

I hope this is helpful.

Thanks Alderbit for the help, I have the material now working and showing a highlight around objects when the camera is looking at them, although it does this for every object, not objects of importance, for example boxes/keys/barrels.

How can I get it so that only objects you can interact with are highlighted? it’s currently highlighted immovable objects.

I’ve tried changing the radius of the Post Processing Object and it’s not helping.

I’m also having a hard time getting the material work in the current engine version :frowning:

Here is a different one that you can try which is from the Content Examples sample project. I tested in both 4.10 and 4.11, and it seems to work fine. All you should need to do is plug it into your post process blendables array in place of the old material. Afterwards you can use the SetRenderCustomDepth function to enable custom depth rendering on objects that should be highlighted.

Download: https://drive.google.com/uc?export=download&id=0Bwkk9IIFWMFbRGVjVm1uYWpiN3c

Sorry Alderbit, still getting the same issue, not sure how to use the SetRenderCustomDepth function to enable custom depth rendering on objects that should be highlighted.

So far I have the blueprints set up, the post process set up and on certain objects that I want highlighted I have ticked under their Rendering details tab, RenderCustomDepth. Still highlighting objects that do not have this selected.

Edit - I’m getting this error too

Error Accessed None ‘CurrentTarget’ from node Set Render Custom Depth in graph ‘Trace’ in blueprint FirstPersonCharacter

Can you please show how you’ve set up the interaction trace?

What you basically need to do is start with all objects having RenderCustomDepth set to false. Then set it to true when they are moused over and back to false after focus leaves them.

Sorry about the poor cropping/screenshot, don’t know how to take a bigger picture, they are label 1 to 3 so you know the order they go in. All my objects and now set to RenderCustomDepth false.

The accessed none error is probably coming from here:

Other than that your blueprint should work. Check the static meshes and make sure they have collision enabled and are blocking the visibility channel. Also check if they have a simplified collision mesh assigned in the static mesh editor. If they don’t you can enable TraceComplex in the LineTraceByChannel function.

Where do I add the IsValid check? this is all still rather new to me and I don’t know much other than what I’ve learnt from other tutorials.

I’ve included two screenshots, one of an object that I want to be highlighted and one that I do not want to be highlighted.

You would just insert the check between the branch node and SetRenderCustomDepth. It’s needed because CurrentTarget might be set to none at that point.

The simplest way to limit highlighting certain objects would be to create a custom collision channel in which to execute your trace.

In project settings you can add a new trace channel.

Name it Interaction and set the default response to Ignore.

86838-newchannel.jpg

Over in your trace function, change the trace channel to Interaction (you might need to recompile the blueprint before the option appears).

86839-setchannel.jpg

Now on any static mesh that should become highlighted you can set it to block the new Interaction trace channel (you might need to recompile the actor blueprint or restart the editor for the channel to show up under Trace Responses).

86841-meshcollision.jpg

Fantastic! thanks for the time you’ve spent to help me do this, learnt along the way too, it’s all working fine now :slight_smile:

hello Alderbit,
I tried to do the same thing you explained above, but I still can’t figure it out. Here’s my set up so far…

I managed to get the render custom depth to be set, but I get an error on the unset render custom depth function. I think because the engine doesn’t have a valid target. How do I set it up properly.
Please, could you help me out?
And would you say, that’s the most efficient way to do it, or is there another more elegant, or performance wise way?

Hi CitéNoir, the problem you’re having is that when the line trace returns false it means nothing was hit, and so the hit result will be uninitialized (and HitComponent will be ‘none’). Also as a general rule you should never try to access the output of a failed cast. It will always be none and you’ll get an error.

The way we did it above was to assign the HitComponent of a successful line trace to a variable at the same time its RenderCustomDepth is being enabled. Then the next time the line trace returns false we use the saved variable as the target for disabling custom depth rendering.

If you find that you need better performance you could do the processing in response to a looping timer with a short interval instead of the Tick event.

Hey Alderbit,
thanks for the reply!
i got it working yesterday, but still with the output of a failed cast.

but as you pointed out, that’s not a good idea. so i’ll try to figure your solution out, seems like a more solid way:)
also it sounds as if it could solve the other issue i got with this, that if the trace gets from one object to the next without not hiting an object that is traceable, the outline effect stays on, on the old object (because the trace remains valid, eventhough the object changed, they still share the same trace channel). but if i got a saved variable as the target, and not just the trace, it should disable the old outline. at least that’s what i hope will happen. still really new to the whole gamedev thing.

and thanks as well for the looping timer advise, sounds like a good idea! made a custom event, that gets called at begin play and a set timer by event from that, that triggers the rest. works like a charm :slight_smile:

so, i’ll see what i can manage with the tracing…

alright, it’s working!!! thank you so much!!!

also my second problem is resolved, because of the set
variable, nice! I can’t quite grasp all of the blueprint logic
completely so far, but i get the concept :slight_smile:
thanks again. cheers n blessings…

for the show interactable icon question by MichaelNoyce and Morosoph, you could just change the style of the crosshair when it’s over the object.if you’re using the linetrace setup by Alderbit, add a texture variable in your hud (crosshair style in my example, picture 01. ignore the show crosshair variable, that’s used for something else) and then do a set crosshair style at the end of the linetrace (picture 02), where you set a texture with some icon that shows the ability for interaction, when over the object, and changes back to the normal crosshair, when not on the object. hope you get what i’m saying.
cheers…

@Alderbit
good evening…
I’ve got another question concerning the linetrace you explained.
I’m trying to get a text box above the item the linetrace hits. I set up a structure for the objects with a text that should be displayed above 'em. this all works (thanks to the epic inventory tutorial) when I use a sphere collision around the objects and when the player is inside that, the text gets displayed. now for the last three days I tried to get it to work not with a sphere collision but with the line trace you showed me how to set up and I just can’t get it to work.
I have two setups, both fail.
the first one:
my linetrace (inside character bp)

then the widget that displays the text

and the bp of the object that uses the text structure which gets displayed by the widget

so, set up like this, it works. but I wanted the linetrace to set the visibility of the text, not the trigger.
but I cant find a way to get it to work inside the linetrace.

@Alderbit
(continued from post above)
my second method was to use a widget component inside the objects bp, that holds the widget that displays the text.
I even managed to get the linetrace switching the visibility of the widget component on and off. but it does so with all widget components at the same time. and only because my linetrace hits any object that the trace is able to hit and not a specified object, like with the highlight material/render custom depth on one particular object. because the highlight object worked so well, I thought I could just use that for the visibility of the text as well, but somehow I screw up along the way. Also I only managed to set the visibility of the widget component and not of the widget that holds the text itself, which is not really intended, but everytime I tried to set the visibility of the text widget, or the text inside the widget or the variable I bound to the text’ visibility I failed miserably. I accessed none or couldn’t set a proper target when trying to cast to the text widget, either from the linetrace inside the bp, or from the objects bp.

pictures for the second method:
the linetrace with event dispatchers at the end (ended up trying those as I sadly couldnt figure out how to get to setting the visibility of the widget inside the linetrace)

and the object containg the widget component

so… after all that long text, do you know any way to set this up somehow? I’m struggling hard.
maybe there is another nice and efficient solution like with the hightlight trace?

anyways, thanks in advance and enjoy your evening.