Getting the number of children of an object in a VERY specific situation...

Now that I’ve finally gotten past that physics blocker, I’ve hit another snag, this time figuring out how to do something in a very specific way.

I’m working on a checkpoint system for my sci-fi racing game. But I can’t figure out an implementation that would work for my particular situation, which is as follows:

  • The checkpoint detection system must be tied to the vehicle, not the checkpoints themselves. If the checkpoints are doing the detection work then it would massively complicate the code or even prevent me from implementing AI vehicles or multiplayer, since I’d have to implement some way of checking the identity of each vehicle.
  • For the same reason, I also can’t just turn the checkpoints on and off. They all have to stay on.
  • It can’t be a “dumb” checkpoint system that just checks to see if more than one checkpoint is passed by the time the player (or AI vehicle) returns to the start-finish line, since that would allow for severe exploits (like this infamous Mario Kart 64 cut).
  • It can’t use a script in any child of “Course” unless those scripts can be called from a script in “Course” that can then pass that onto wherever it needs to be used, as seen below. This means no using FindObjectsWithTag either, since I’d have to tag not only the checkpoints themselves but the objects containing them as well, and that would result in more than just the checkpoints themselves being returned.

I’m just looking for suggestions to get me on the right path so I can hammer out some code and get this working. I know I need to get the number of checkpoints (and later the position data of each checkpoint), I just need to know how to do that in my particular situation.

Is transform.childCount not working for you?

EDIT: I had a brain fart. I’m thinking about this the wrong way and over-complicating things. I forgot I could just set a variable in my controller from a script in the “checkpoints” object.