Everything worked fine. I tried to add a child actor component and I got this crash coming from LineTrace Function even tho it had nothing to do with it. I removed all the new code and I still got this error. What do I have to do? If you need any additional code to show you please let me know. LineTrace function is being called every tick. HitResult is a UPROPERTY() FHitResult
Thanks everyone!
ignore the outhit i wanted to test the pass by reffernce. In addition when i removed the line trace from the tick and put it in the interact action(left mouse button), it crashed when it triggered of course and i got a warning in editor ““accessed none trying to read property camera”. Camera is my first person camera component. I have no sprign arm
My game is third person and i have gun i put socket on my gun and name it barrel socket and in block of if(Barrel socket) i wrote these codes for linetrace i hope it helps you :
I don’t see where your FHitResult& outHit
is being assigned too I will presume that this is being obvuscated as typically for a line trace function the parameter FHitResult& HitResult
is effectively the “outHitResult”.
also the if you are not going to do anything with the bool return
(if a blocking hit was registered) then you don’t need to capture it.
for the what I think the matter at hand is. does this “child Actor” have collision volumes of any kind be it capsule, box, or mesh. check the physics channel that the collider is on. if you have reasons not to change that channel, or you don’t think your designer(s) will adjust whether the Actor has collision, or the collision Channel then you might want to consider
adding the entire actor hierarchy to the ignore list
// ....
FCollisionQueryParams Params;
Params.AddIgnoredActor(this);
// for blocking hits
if(GetWorld()->LineTraceSingleByChannel(outHit, Start, End, ECC_GameTraceChannel1, Params))
{
HitResult = outHit;
}
// if you want to be explicit, and overlaps are acceptable
GetWorld()->LineTraceSingleByChannel(outHit, Start, End, ECC_GameTraceChannel1, Params);
if(outHit.GetActor() != nullptr)
{
HitResult = outHit;
}
by adding FCollisionQuaryParams.AddIgnoredActor(this)
anything that would be returned by GetComponent()
or GetOwner()
will be ignored in the line trace.
then if you are getting an Exception_Access_Violation
that probably means you missed something along the lines of if(HitResult.GetActor() != nullptr)
because there is the situation where the Line hit nothing, and trying to access a member of nothing is in the best case a crash, and the worst case absolute bad day garbage.
there are other reasons the HitResult->GetActor() might be null as well like. for some reason it was invalidated by GC, or it now points to something else, and the manager didn’t move your pointer when the reassignment happened
Thank you for your notes! I deleted the BP_Ethan character and I replaced it with a new blueprint from the c++ class and it worked. Why did that happen. Did it mess something up trying to attach the child actor on the original Blueprint? But then I commented the code as if I never tried to attach something and it still wasnt working? Am I missing something? The problem seemed to be the camera component like when I attached the actor it became nullptr or something
Yes thank you! I will put a if to check if the pointer is null, but the camera seemed to be the problem. After I attached the child actor it started crashing, and even after i deleted the code it kept happening. I replaced the old bp character with a new one and everything is working for some reason, like if the blueprint got corupted or something