Project Crashes when Projectile Collides With Pawn

My Project Crashes every time my projectile hits a pawn.
I tried deleting the intermediate and binaries folders and rebuilding from vscode but that didn’t work.
I also tried recreating the BP_Projectile Blueprint but that didn’t work either.
Any help is appreciated.

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffffffffffff

ucrtbase
ucrtbase
ucrtbase
UnrealEditor_Core
UnrealEditor_ToonTanks_6008!DispatchCheckVerify<void,<lambda_637e81ca31fd3650f5ea3d6907598964>,FLogCategoryLogTemp,wchar_t [11],float>() [X:\Epic Games Games XDrive\UE_5.0.3\UE_5.0\Engine\Source\Runtime\Core\Public\Misc\AssertionMacros.h:170]
UnrealEditor_ToonTanks_6008!UHealthComponent::execDamageTaken() [C:\Users\Name\OneDrive\Documents\Unreal Projects\ToonTanks\Intermediate\Build\Win64\UnrealEditor\Inc\ToonTanks\HealthComponent.gen.cpp:31]
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_ToonTanks_6008!AProjectile::OnHit() [C:\Users\Name\OneDrive\Documents\Unreal Projects\ToonTanks\Source\ToonTanks\Projectile.cpp:52]
UnrealEditor_ToonTanks_6008!AProjectile::execOnHit() [C:\Users\Name\OneDrive\Documents\Unreal Projects\ToonTanks\Intermediate\Build\Win64\UnrealEditor\Inc\ToonTanks\Projectile.gen.cpp:34]
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll





On line 41 in DamageTaken you used %s which is for strings, Health is a float not a string. You need the %f specifier.

Thank you! that fixed everything. how does having a string instead of a float there cause the whole engine to crash? I would hope that the compiler would give me an error instead, or the crash log would direct one to that problem.

That would require the compiler to specifically understand that piece of code. Whilst compilers can warn on mismatched printf specifiers e.g. example (Unreal uses one of the printf family of functions in the implementation)
That is far removed from the call to it.

UE_LOG(LogTemp, Warning, TEXT("Health: %s"), Health)

This macro expands to

{ 
    if ((ELogVerbosity::Warning & ELogVerbosity::VerbosityMask) <= ELogVerbosity::VeryVerbose && (ELogVerbosity::Warning & ELogVerbosity::VerbosityMask) <= FLogCategoryLogTemp::CompileTimeVerbosity) 
    {
        static_assert(TIsArrayOrRefOfTypeByPredicate<decltype(L"Health: %s"), TIsCharEncodingCompatibleWithTCHAR>::Value, "Formatting string must be a TCHAR array."); 
        static_assert((ELogVerbosity::Warning & ELogVerbosity::VerbosityMask) < ELogVerbosity::NumVerbosity && ELogVerbosity::Warning > 0, "Verbosity must be constant and in range."); 
        if (!LogTemp.IsSuppressed(ELogVerbosity::Warning)) 
        {
            DispatchCheckVerify([](const auto& LCategoryName, const auto& LFormat, const auto&... UE_LOG_Args) __declspec(code_seg(".uedbg")) 
            {
                if (bool(LogChannel)) 
                {
                    static bool __LogPoint93; 
                    if (!__LogPoint93) 
                    {
                        FLogTrace::OutputLogMessageSpec(&__LogPoint93, &LCategoryName, ELogVerbosity::Warning, "PathTo\\File.cpp", 93, L"%s");
                         __LogPoint93 = true;
                    } 
                    FLogTrace::OutputLogMessageSimple(&__LogPoint93, LFormat, UE_LOG_Args...);
                } 
                { 
                    FMsg::Logf_Internal(nullptr, 0, LCategoryName.GetCategoryName(), ELogVerbosity::Warning, LFormat, UE_LOG_Args...); 
                }
            }, LogTemp, L"Health: %s", Health);
        };
    } 
}

(no prtintf in sight)
So the use of the format specifier and the argument for it just look like a normal function call. To the compiler it has no idea that they’re for printf.


printf is not type safe, it has no idea about what the types are (which is why you have to spell it out for it). Providing the wrong type for the specifier is “undefined behaviour” (UB) so quite literally anything can happen.
Once you’re in UB land there’s usually not much point discussing why something happened happened, because literally anything is on the table when you enter UB.

With that said it most likely crashed because the program tried to access memory it wasn’t allowed to so the OS shut it down. This is because in order to format a string it would need to know where it ends, it’ll keep reading bytes until it reaches the null character in order to do so; which is a problem if it’s not there.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms