I have a gun setup as a custom component, with a float variable to keep track of when to shoot. I set it to 0.0f in the component’s constuctor (and even tried in BeginPlay() instead). Then, the only other place it’s used is in the component’s firing method.
// The firing function
39. void UBaseGunComponent::Fire(float DeltaTime)
40. {
41. if (fireTimer == 0.0f)
42. {
43. // ToDo - Shoot
44. }
45. else if(fireTimer >= 1000 / rateOfFire)
46. {
47. fireTimer = 0.0f;
48. }
49.
50. fireTimer += DeltaTime;
51. }
When I try to set fireTimer to a new value in the method, the engine crashes and throws up an access violation error. The error reporter says that the violation occurred at line 40, but if I comment out the assignments to fireTimer, it doesn’t crash which is why I think it has something to do with the variable assignments.
The Fire() method is called from the parent actor’s Tick() method.