Racing Game - Laps double after all checkpoints cleared, instead of increasing by 1

Hi All - let me preface with that I am a novice in blueprints.

I have been following the Unreal Time Attack race car checkpoint system tutorials from about 6 years ago, and everything seems to work except that my laps increase by 2 instead of 1 each time I complete a lap. (ie. if its a 7 lap race…it goes from lap 1, to lap 3, to lap 5, to lap 7) and I have no idea why.

I’ve attached a few blueprints from the Tracker and PlayerController where I think the problem may lie, but I’m stumped and any advice would be appreciated. Thanks

One of the pics is a little fuzzy and I can’t see anything crying out to be fixed there, except…

You have nested for loops on the checkpoints, which is probably not what you want:

Sorry for the fuzziness, here is a clearer image (hopefully).
And yes, I noticed in the comments section about this double loop. Someone wrote (but unfortunatly, I don’t fully understand)
Fixes ForEachLoop:

  • 1st ForEachLoop [Completed Pin] <—> SET Total Checkpoints
  • 2nd ForEachLoop [Completed Pin] <—> Play Level Music

Any thoughts on how to fix? And thank you for trying to help me out.

If you have 10 checkpoints, everything in that second loop will run 10 times per loop… 100 times by when the first loop is done.

Thanks, I believe I made that change, but unfortunately my laps still double. Thanks for your suggestion though.

My guess this is the actor you need to check:

I added a print text at the end (see photo) and noticed that when I passed through the last checkpoint, both a 3 and a 2 appeared - as if the UpdateLap event is being called twice?

Sorry, I think you still need to look at this piece of code, it makes no sense. You’re doing this:

Foreach checkpoint:
get checkpoint number from index ( fair enough )
set total number of checkpoints ( for every checkpoint?! )
activate checkpoint ( how does it know which one? )

Now, before the loop has finished, start the next loop:
Bind an event ( you only need to bind once on begin play )
and some other stuff.

The point is, if you have 5 check points, this stuff will get called 25 times!


1 Like

Hey ClockworkOcean, thanks for your reply, and yes, I agree this makes no sense. The Unreal instructor built it this way, and I am too green in scripting to figure out the correct change. I did however reach out to the UE4 Drivable Cars community (they sell prerigged cars in the marketplace) and they offered this suggestion:

@Doogalson is your game multiplayer? If so there may be replication causing it, as it will be counting the lap from the client and the server generating the 2nd lap you could probably use a “Has authority” node or “is locally controlled” node at the start of your lap counter code, should hopefully stop it counting twice

This seems more closer to a solution for my problem, because when I complete a lap I see a 2 then a 3, as if two cars went through. After seeing the code I have posted earlier, any suggestions on how to place those node? (I did try to place them where I thought would be correct, but no luck).

Is it MP? I think you would know…

I just look again, it’s worse than I thought:

The loop is not only calling the 2nd loop every time around, it calls it AGAIN on the end, for good luck presumably :slight_smile:

Try removing that complete pin and moving this here:

It’s not supposed to be and it’s meant to be a single player game, but the assets I am using are designed for multiplayer (UE Drivable Cars)

Ok thanks! I’ll make that change

Tell me if it works…

That seemed to work! Thanks for your time and advice.

And I was able to fix the lap issue as well. Drivable Cars TechSupport suggested I add a “Has Authority” node before I cast to the BP_BaseCar. BUT more importantly, instead of “On Component End Overlap” we switched to a “Begin Overlap” I wish I knew what that all meant, but it works now for my purposes. Thanks again for you time.

1 Like