It debugs visual studio , when i hit play butn in editor , the error message comes up i send the bug report , and then when i came back to visual studio thats what appeared. Also there are no errors on the code , as far as i know
Well i belive its an invalid object cause the code i have is pretty simple , and before the error came up , i had tested this part of code and it was working fine
void AWeapon::Fire()
{
if (ProjectileType == EWeaponProjectile::Ebullet)
{
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Bullet"));
Instant_Fire();
}
if (ProjectileType == EWeaponProjectile::ESpread)
{
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Spread"));
for (int32 i = 0; i <= WeaponConfig.WeaponSpread; i++)
{
Instant_Fire();
}
}
if (ProjectileType == EWeaponProjectile::EProjectile)
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Projectile"));
}
From what you tell me, this happens as soon as you hit Play, which is strange since you should not be calling Fire() at that moment. If this is indeed the case, your Fire() is probably being called at a moment where GEngine is not yet valid, which is strange.
Which line is line 20?
Also, try adding this at the beginning of the function and see if it works:
Then there is an issue with ProjectileType. I’m assuming this is an enum, how is that enum declared in your weapon.h file? I’m thinking you may have missed the UPROPERTY() macro ?
That or the stack indicate that line and may have crashed on the other one, try if(!GEngine) return; jus tto be safe too.
I have to leave for the night, but here is the proper way to declare an enum, since it looks like that may be the problem here:
UENUM()
enum EWeaponProjectile
{
EBullet,
ESpread
EOtherType,
EOtherType02
};
//And here how to add a member of that type in your .h
UPROPERTY()
TEnumAsByte<EWeaponProjectile> ProjectileType;