hi, playing around unreal , i am stuck in process of casting, basically i have a playercontroller class(character) through which i am raycasting to hit a turretclass(pawn), however
PlayerController.cpp
AActor* hitActor = hit.GetActor();
if (hitActor)
{
UE_LOG(LogTemp, Warning, TEXT("hit object name %s"), *(hitActor->GetName()));
if (hitActor->ActorHasTag("Turret"))
{
//ERROR HAPPENS HERE
/*ATurret* turret = Cast<ATurret>(hitActor);
if (turret)
{
turret->TakeDamage(10);
UE_LOG(LogTemp, Warning, TEXT("damaged object name %s"), *(hitActor->GetName()));
}*/
}
}
Error log
Access violation - code c0000005 (first/second chance not available)
UE4Editor_TP_4865!ATurret::Dead() [c:\users\suhail\documents\unreal projects p\source p urret.cpp:78]
UE4Editor_TP_4865!ATurret::TakeDamage() [c:\users\suhail\documents\unreal projects p\source p urret.cpp:73]
UE4Editor_TP_4865!APlayerCharacter::GetFirstHit() [c:\users\suhail\documents\unreal projects p\source p\playercharacter.cpp:329]
UE4Editor_TP_4865!APlayerCharacter::Shoot() [c:\users\suhail\documents\unreal projects p\source p\playercharacter.cpp:261]
UE4Editor_Engine!FInputActionUnifiedDelegate::Execute() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\classes\components\inputcomponent.h:196]
UE4Editor_Engine!UPlayerInput::ProcessInputStack() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private\userinterface\playerinput.cpp:1243]
2nd question: i am trying to rotate turret towards player location in range, i am able to set bool when player is in range but however, i need to know how to rotate it, i tried FINDLOOKATROTATION() but i dont see an example to use it on c++
3rd how to decide if i must create an actor or pawn class, or make an component class? lets say i am making a game with bots and pick items, for now i have set pick up items have an actorcomponent script, i have made turret using pawn class(should i have made it using actor class?), its quite confusing atm.
Your access violation is inside the
ATurret::Dead()
function.
In the Game Framework’s logic Pawn (along with Pawn-derived classes like Character) is something that can be possessed by a Controller. Therefore if your game does allow your players and/or bots to control turrets then your turret should be a Pawn. If your turret is just a level object to be destroyed then it should be an Actor.
And about Components: you can create multiple reusable Components for your Pawns/Characters and then create multiple Pawn- or Character-derived classes that combine different sets of these Components. Think of a Component as of an ability or property of an actor and think of Pawn-derived classes as of different kinds of Pawns.
myActor->SetActorHiddenInGame(true);
// Disables collision components
myActor->SetActorEnableCollision(false);
// Stops the Actor from ticking
myActor->SetActorTickEnabled(false);
removing myactor reference solved the bug, it seems assigning myActor = GetOwner(); doesnt do anything, also i am trying to use Findlookatrotation through blueprint it ends up crashing aswell…
Access violation - code c0000005 (first/second chance not available)
UE4Editor_TP_3436!ATurret::Tick() [c:\users\suhail\documents\unreal projects p\source p urret.cpp:43]
UE4Editor_Engine!AActor::TickActor() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private\actor.cpp:863]
UE4Editor_Engine!FActorTickFunction::ExecuteTick() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private\actor.cpp:125]
UE4Editor_Engine!FTickFunctionTask::DoTask() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private icktaskmanager.cpp:269]
UE4Editor_Engine!TGraphTask<FTickFunctionTask>::ExecuteTask() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\core\public\async askgraphinterfaces.h:883]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\core\private\async askgraph.cpp:954]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\core\private\async askgraph.cpp:701]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\core\private\async askgraph.cpp:1798]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private icktaskmanager.cpp:538]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private icktaskmanager.cpp:1450]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:758]
UE4Editor_Engine!UWorld::Tick() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:1373]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4+release-4.15+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1630]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.15+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:391]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3025]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\launch\private\launch.cpp:166]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:134]
UE4Editor!WinMain() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:210]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll