The only time when the engine crashes because of the cast is when the enemy fires it’s gun. If the Enemy does not fire the crash does not happen. At line 29 the engine shows that there was a problem attaching the line trace to the socket. I don’t know maybe I am attaching/and or firing the line trace wrong but I doubt it. The crash is where the line says
I tried this but for some reason the
linetrace still does not fire.
Still crashes or does not execute?
If EnemyWeaponBaseMesh is null, then if(EnemyWeaponBaseMesh) will be false and whatever comes inside the if will not execute. So if EnemyWeaponBaseMesh is null (I would check whether or not it is null, if it is then you need to solve that, if it is not, then that is not causing your problem), then the solution is to properly set it, so that it points to something valid.
If you’re already using C++, start UE from visual studio and reproduce the crash. Then inside visual studio look at the line where it crashed (it will be shown there) and at all values of the relevant variables for that line of code.
I placed the line trace function inside of the AI it self instead of casting to the firearm and it worked. I just attached the linetrace to the socket of the weapon that I had created a default sub object of and attached to my character within the character. I did not spawn the weapon I just attached the weapon within the class hierarchy then attached the linetrace to the socket of the weapon mesh inside of the character and the mesh did not make the engine crash.