Casting from a widget blueprint to an actor

Hello.

I am trying to cast from a widget blueprint to an actor, but it doesn’t seem to be working. I have created an actor object reference to plug into the object input of the casting node and I feel like this may be the problem, but am unsure what the solution is.

For reference, I want the text to be invisible, unless the player is within a certain distance of and object (im trying to make a detection system that will increases the nearer the player gets to an object, so if anyone has any entirely different ideas on how to do this that would also be greatly appreciated).

Thanks :slight_smile:

1 Like

Does this widget belong to the artefact? Or is it part of the player - as in, the player has an aritact scanner / detector?

  • there are (invisible?) objects in the scene
  • we walk around
  • when we get close enough to an object, a widget pops up above it because we’ve detected it?

Is this the rough scenario?

so the idea is there are objects hidden underground. As the player gets closer to them, there is a bar that would fill up more and more the closer the player gets. :slight_smile:

1 Like

And this bar and text, the widget you’re showing - each artefact has its own? Or the player has one widget that shows how close they’re getting to something?

oh right sorry, the text was just a place holder as im currently trying to just make sure I can hide/show the widget as id like.

each artefact shares the same widget- the widget is actually created in an artefact detection actor that is essentially a place holder for the actual artefacts since you won’t be able to see them under the ground.

I hope that makes sense

I hope that makes sense

Sadly, nope.

Yeah, no :innocent: We need to unpack this. I’m not getting it.

each artefact shares the same widget

So the artefact owns the widget? Is this how the artefact actor looks like?

the widget is actually created in an artefact detection actor that is essentially a place holder for the actual artefacts

But then no, there is also an artefact detection actor that is placed in the level instead of the actual artefacts?

Colour me confused but do tell more. Is there a sketch?

no sketch but I can send another picture of the blueprints involve that I think will help


This is the blueprint for my “ArtefactDetection” actor. It measures how near the player is to it as well as which of each “ArtefactDetection” ref is closest.

I am looking to create a bar that increases/decreasees in how full it is based o how near the player is to the “ArtefactDetction” actor.

-For context, the goal of the game is to find an artefact under the ground (the “ArtefactDetection” actor) at which point they’ll have to answer a question. getting the question. right will allow them to unlock an actual artefact-

:slight_smile:

1 Like

This widget needs to know the distance and/or the reference to the closed artefact?

If so: select this node:

image

And flag it as Instance Editable and Exposed on Spawn in its details panel. You’ll get a new pin on the Create Detection WB Widget node where you can plug in the closest actor obtained by fetching a reference from the Out Actors with Closest Index.

You can then use this reference inside the widget.

thanks so much.

You had me until “Out actors with closest index”, not sure how id get that reference.

Or maybe I do know but I’ve misunderstood what you said.

Thanks again :slight_smile:

You’ve done a lot of hard work to find the Index of the closest actor:

Consider the following:

  • does the widget really need to know the reference of the artefact actor? The widget’s job is to show the exciting UI bits - perhaps the widget should be told the distance to display and told how to behave rather than made look for actor refs and extract their data.
  • instead of using the Get All Actor of Class node, you could instead try:

Perhaps there is no need to iterate over 1000 artefacts? Perhaps we can find just the ones that are close by and only sort those by distance? This is irrelevant if you have 10, very relevant if you have 10k. For this, the artefacts (or their placeholders) would need to have some form of collision.

  • this widget:

Is not referenced (bar the the viewport holding onto it). If you ever call this script again, you will orphan the existing widget and create a brand new one. Again, this may be utterly irrelevant, may you only need to detect the artefacts once or something else makes this widget obsolete.

oh right yh I get that bit.
Im unsure what you mean by “out actors”. Simply plugging the Closestindex variable into the create widget blueprint im assuming wouldn’t even allow it.

These are the actors you found and are now sorting by distance. Eventually you find the one that is the closest by distance, and its index. You can use that index to fetch the correct artefact reference form the Out Actors array.

Simply plugging the Closestindex variable into the create widget blueprint im assuming wouldn’t even allow it.

The widget needs an actor reference, not merely and index.

okay. so I now have this in the artefacts blue print

and this in the widgets blue print

I think at least hat now everything is working, but I can’t eb sure as the cast still seems to be failing, cannot think why.

How many actors are there in that array?

well it would vary each level but currently there are 3

Hold on.

I was under the impression you wanted to access the artefact itself in the widget. But you want to just access the Detector itself. Pass Self here instead:

Also, you will not need to cast anymore.

oh right sorry im with you now

I haven’t touched the default value so it’s still set at 0

Nah, that’s fine - the Get All will populate it. See above. My bad.