Cast To Blueprint Interface does not work (returns value from unkown)

Hello,

I got stuck at following problem:
The first time i hit something with trace everything works fine, but as soon as i dont hit the object anymore, the cast still returns a valid casted object and that from an “unkown” input.

I dont get why, it seems like the out value from the Cast is cached and taken from when i first hit something with the trace, but that does not seem to make any sense.

Following shots are while in debugging/simulation at same breakpoint, how is that possible? (box trace does not hit anything here (return value is false))

1 Like

I think nodes with an execute pin do cache results, so that might explain something.

However, the whole point of using interfaces, is not to use casting. So it’s really one or the other, no point in mixing them.

And ( sorry to drag on ), but I notice what you’re doing here, is a interaction highlight system. I can tell you from writing one myself, and helping others with this, that it’s not possible to ‘un-highlight’ from a central piece of code like this.

Imagine I have a book on a table, and both are interactive. I mouse over the book, it highlights, but then I move the mouse onto the table. The system now can’t un-highlight the book, because the table is now the hit actor. It’s even worse if you have a timer on the highlight.

The solution is, to write a parent interactive blueprint that knows how to highlight itself. Then, all you have to do, is send it the highlight message, via an interface and you’re done :slight_smile:

Thanks for the reply. WIth caching I meant “between 2 ticks” that would be a big flaw or am i wrong.

And ( sorry to drag on ), but I notice what you’re doing here, is a interaction highlight system. I can tell you from writing one myself, and helping others with this, that it’s not possible to ‘un-highlight’ from a central piece of code like this.
For that reasion i (want) unhint the object as soon as i target a new/different non hintable object (it was the plan at least). For that reason i also checking if the current highlighting object matches the one targeted in the last frame.

I will rethink about your logic, but for educational interrest, where is the error in my implementation. That caching idea was an educational guess but i cannot imagine its realy the problem, since it would break so many programming paradigms.

You set the BP expectation bar too high. This will totally work in BPs and it’s totally unsafe:


There are so many grey areas where you need to police things yourself. Pure function come to mind for example:

The main difference is that Pure Functions promise not to modify state or the members of the class in any way […]

Yeah, the thing is that they do not work like this at all. It’s for you to enforce it.

1 Like

You can use DoeImplimentInterface but you dont even need that with interfaces.

Just cache the previous hit actor, call EndLookAt Message if valid, set hitactor then call StartLookAt Message

1 Like

The problem is here

The cast fails, you then proceed to use the yellow pin later on, even though it’s not a blueprint.

Does this code come from a YT tuut? I had this exact discussion with someone else last year. They persevered for nearly a year, before realizing you can’t always remove the highlight from objects.

No not by a tutorial, just from me (im a professional programmer but not in blueprints so its VERY astounding that when the cast fails you get a valid object back WTF).
I will later try your aproach (just check if the object implements the interface by using “implements” function, which i did not find before (searching for docs about blueprints is still not that easy, i often dont find what i need, in other langs its easier).

Does this code come from a YT tuut? I had this exact discussion with someone else last year. They persevered for nearly a year, before realizing you can’t always remove the highlight from objects.

I dont quite understand what you mean? In my case i just want to show/hide a text on the object it self if you look at it and allways only one object, to indicate that user can interact with the object.
BUT! its just prototyping phase. The bigger problem was the weird behavior of the casting function.

1 Like

Yes, that kind of thing.

You’ll find that setting and unsetting a variable is not enough, in the end. Because the player can mash the mouse around quickly and the code won’t have time to catch up.

1 Like

I had a bit more time, here’s what I was trying to recommend. In the player

That’s it, nothing else.

In the parent interactive BP

( yes, it’s a text render, but could easily be a widget )

BPI

1 Like

Mhh

You’ll find that setting and unsetting a variable is not enough, in the end. Because the player can mash the mouse around quickly and the code won’t have time to catch up.

I doubt that there is a catching up problem, since the code is still should be executed in a deterministic way.

But your second aproach is still far more easy.

1 Like

It also allows for a nice fade or timeout on the highlight, you otherwise wouldn’t be able to pull off :slight_smile:

1 Like