Actor pointing to null but if (Actor) returns true

Hi Everyone,

I’m not sure if I understand how Unreal Pointers work correctly.

I normally use if (Actor) to see if the pointer has a value. Is what everybody recommends and I have been using this everywhere.

This works everywhere but in this specific piece of code:

AFocusableBase extends from AActor and I call this public method from an external different Class.

This is the value of Focused Actor when I debug it but if (FocusedActor) still returns true.

I have tried this too, but same result:

I checked, but Focused Actor is still null:

Is there anything that I am missing?

Cheers,

Bullyproof

Are you using a “debug” instead of “development” configuration in VS? I’ve found that you can’t really trust the debug output in VS when using a “development” configuration.

Do you mean the Solution Configuration?

I am using Development Editor, I get the same result when I compile from editor without using the VS Local Debugger. It crashes:

Access violation - code c0000005 (first/second chance not available)

“”

msvcr120
msvcr120
msvcr120
UE4Editor_Core!FMsg::Logf_Internal__VA() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\private\misc\outputdevice.cpp:549]
UE4Editor_DisturberVer1!ADisturberBall::Use() [c:\users\movethirtysix\documents\unreal projects\disturberver1\source\disturberver1\disturber\disturberball.cpp:19]
UE4Editor_DisturberVer1!AMainCharacter::Action() [c:\users\movethirtysix\documents\unreal projects\disturberver1\source\disturberver1\characters\maincharacter.cpp:128]

[link text][2]

I solved the Crash, it was a matter of removing %s in the String when it didn’t have a value, but I still don’t understand why Visual Studio returns true when if (Actor) in that specific piece of code…

It’s the other way around, as Daniel Ricci pointed out, It is Development editor the one who has funny behaviour. Honestly I still don’t understand why. Thanks for your answer!

Is it possible that your pointer is a smart pointer handled in such a way that you need to call a function to check if its valid? Also can you try compiling your game under Debug Editor, if thats to slow you can always remove optimization in the PCH files.

That was it. I debug it using Debug Editor and it worked. I still don’t understand the differences between the different Compilers, thanks!