Checkpoint Manager not sorting out the checkpoints in the correct order. Possible Array issue?

Hello,

Im working on a side scroller platformer for a uni project and I have created a checkpoint system for it with a respawn. However when I load it up, the checkpoints don’t function logically. (i.e Run over the first checkpoint, respawn at the last checkpoint)

Below are the blueprints I am running for the checkpoints + manager. What could I be doing wrong?

Thanks in advance.

I’m not 100% sure if your issue is the checkpoints aren’t going into the array logically (checkpoint 1 in index 0, checkpoint 2 in index 1, etc.) or if you are having problems getting the proper checkpoint(s) when you “Get” them?

I’ll try to give help in both cases. The “Get All Actors Of Class” doesn’t know that your checkpoints are labeled “1, 2, 3, 4” so therefore will grab all the instances of that class in whatever logical order the function determines.

The next issue is you “Get” an index from your checkpoint array where you logically think (and would expect) that checkpoint reference to be; however, it isn’t in that index because of the issue listed above with “Get All Actors Of Class” node.

What I would suggest is, use your “Get All Actors Of Class” for your checkpoints, then For Each Loop on it but instead of using “Insert” to put the checkpoint into your array, use “Add Unique” which will ensure only unique checkpoints go in (no doubles of the same instance but you can have multiple of the same type.)

Then, have 2 variables of the same type your checkpoint is, (not an integer like you have it now) one for “Active Checkpoint” and one for “Previous Checkpoint”. When your character runs through a checkpoint, have the code “Set” the “Previous Checkpoint” from the contents of “Active Checkpoint” (do an “IsValid” check before doing this to ensure you have something stored in “Active Checkpoint” or you will get NULL pointer.) Then have the code “Find” the instance of the checkpoint he is passing. The “Find” node returns the index of the item you are looking for. You can then use that index from the “Find” to “Get” the instance you want from the array.

Sounds more complicated than it actually is but is the best way for you to do it. If you still don’t understand what I’m talking about, let me know and I can try to create a simple project to take some screenshots for you.

If this helps, do me a favor and accept the answer by clicking the check mark next to the answer. You’ll know you got it right if the answer highlights green! Thanks!

Thanks for the reply!

The main issue was that when I ran over checkpoint 1 near the start of the level and died, it would spawn my at checkpoint 4 at the top of the level. The array does grab all the checkpoints but it doesn’t order them correctly.

I’ll give this a try when I get back from work later. It sounds pretty straight forward to follow but i’ll reply back with my findings or problems.

If this sorts it out, i’ll make sure i’ll tick the arrow. :slight_smile:

Alright, let me know… And it’s the check mark but also checking the arrow is always appreciated :slight_smile:

I changed the Insert to Add Unique and it worked. Thank you so much! :smiley: