Normal Cast vs Pure Cast - Accessed None

Casting to a custom player controller:

The cast does not fail, the print string does not fire, the execution works fine but the log produces the following:

[HR][/HR]
The same but with the cast converted to Pure:

Works fine and the log is clean. The whole thing is triggered by widget’s onMouseLeave event.

Any ideas why would the normal cast produce something bizarre like that. Or am I missing something obvious?

It could be because you are also connecting the Failed pin into the Branch, which will try to still read the variable when the cast fails.

Other than that /shrug

Thanks. I had tried that; as I said above the Print node does not fire. :expressionless: Odd.

Looks like a bug to me.

It’s in widgets - there are a ton of sneaky little issues in widgets, I suppose it’s during the slate pass or something?

It’s triggered by *onMouseLeave *event. I have generally avoided casting or any heavy lifting in widgets so this caught me by surprise. If I manage to isolate/reproduce this in a clean project, I’ll put it up on answerhub. Thanks everyone.

Do you mean by the picture that you posted, or did you disconnect the execution pin after the print string at a later time and retested?

I have tried half a dozen things by now, here’s the best demo:

As you can see, the execution flow is fine and, most importantly, everything works as expected. The cast does not fail, the Print String does not fire. The output log throws the Accessed None error I mentioned in my initial post. Interestingly enough, **the error is gone once this dynamic cast gets converted to its pure version. ** - that’s the puzzling bit.

It’s not particularly bothersome, it’s just quirky. Anyway, I’ll shove it under the carpet for now. I find it hard to disagree with @at this point. :confused:

I can’t tell you for sure without digging into the source code of how the two are implemented. But my guess is, the pure cast also has the same issue, it’s just not throwing the warning because it’s not really being executed (I think).
Whilst the non-pure one does throw the warning.

I think it’s like dynamic- vs regular cast.

I think it’s dynamic and regular? anyways I hope this helps you a bit even if it’s a bit off.

To elaborate a little bit on my previous statement, I remember when I used Unity years ago and working with that ui framework, I remember reading that every frame, the ui made two passes - the first time to calculate where everything should be and the second time actually drawing the elements. This meant that if I executed a variable ++ code, it would do that twice, so it would be like var+=2. It also resulted in a few other quirkyness, though I have no doubt that results from me not actually knowing much about the system.

Now, I don’t really know how slate works. But I have come across several of these little “that should work… but doesn’t” moments.
Here’s an example - The relevant part in the linked post, for this topic, is the last picture showing the printed strings: Clear Timer by function name - partially working? - Blueprint Visual Scripting - Unreal Engine Forums
Notice how the print string that verifies that the timer should clear is printed, but the timer is actually never cleared.
That problem has been worked around, it’s just an example of how executing code through a widget event may have unexpected results.

Another thing I have noticed is that during a drag & drop event, the engine does not warn about “accessed none”.
If you create a drag and drop event and a way to trigger it, now add an actor reference variable to the widget. But never set it. Inside the Drag & drop function you can now get and set variables of that empty variable, but as you print string: is valid(), it will print “false”. Yet no warnings.

There are also a few situations where the only way to have something happen properly inside widgets, is by executing it on the next frame (for example using a “set timer by event” with a value of 0.00001).

I could go on, but it’s either too specific, overkill because you’ve already gotten my point, or I have forgotten about them. I should start making a list.

@ & @ste1nar, thanks for your input on this. I understand pointers relatively well (even more so now after following the link) but the nuances of how blueprints pull certain behaviours off elude me at times.

Was not aware of this, sounds like a little debugging nightmare - will keep my eyes peeled for those.

Thanks again.

Why do you still have the Cast Failed pin connected to the flow of execution? Disconnect the White Pin after the Print String and let me know if you still get these errors.

Debugging purposes - to see if the cast fails, to test the flow, to isolate the issue - that’s what this pin is for (amongst other things)

Not sure why that would make any difference whatsoever. But just to humour myself, I did as suggested; same story, no dice.

[HR][/HR]
If you are trying to understand what I mean, have a look at these; both work, but the top one throws Accesses None error:

&stc=1

The widget is very simple:
[root] (self hit test invisible)[border] (shti)[INDENT][overlay] (shti)[INDENT][button] (visible)
[image] (hti)
[vBox] (hti)

[/INDENT]
[/INDENT]

The button is the only thing that is interactive here, also checked with with widget reflector.
And that’s the only widget that exhibits this behaviour, tested with some other random ones and casting works fine.

Meh.

Well, unfortunately it didn’t work, but when debugging you must remove any element that could be causing the error, especially when that element is incorrect code. I understand that you want a print string on cast failed, which is fine, but continuing the execution chain as if it succeeded is not good practice. In C++ using a null pointer would lead to an Editor crash =x.

My last idea is to replace the ‘Get Player Controller’ node with ‘Get Owning Player’, as this is the standard node to use in Widgets. Just be sure to set the Owning Player on the Create Widget node.