InvokeRepeating() doesn't work with 0 as input?

Hi,

I’m a little confused about InvokeRepeating(). I’m mainly using multiple calls to InvokeRepeating() in Start() to repeatedly call some of my own functions that record the current position and angular velocity of a player controlled object as well as the current time.

void Start () {
        positions = new List<Vector3>(); // initialize array...
                                         // and start recording after tSamples	
        angVels = new List<Vector3>();
        com = new List<Vector3>();
        time = new List<float>();

        rb = GetComponent<Rigidbody>();
        com.Add(transform.TransformPoint(rb.centerOfMass)); // Converts         COM coors to global instead of local, 
                                                            // is this what you want?
        InvokeRepeating("RecPoint", tSample, interval);
        InvokeRepeating("RecAngVels", tSample, interval);
        InvokeRepeating("RecTime", tSample, interval);
}

So since I want to start recording data as soon as the game starts I set tSample = 0.0f and I set interval = 0.1f so that I would grab data every tenth of a second, or get 10 data points every second. Is this approach logically sound or am I misunderstanding something about InvokeRepeating(), particularly about the start time parameter?

I’ve got a GUI button set up that calls CancelInvoke() once for each of the calls to InvokeRepeating() and transfers the stored data into different text files. My issue is that when tSample = 0.0f and I hit the button to stop recording values within 10 seconds I get no data stored at all. If I let the game run for 10+ seconds I’ll start to store data just as I would expect. But I really need to start grabbing that data at the start or as close as I can get to it.

With my current set up, if I wait 3 seconds before hitting that button I would expect to get 30 data points for each quantity, but right now I’m getting nothing. If I wait 11.47 seconds I get 22 data points instead of the expected ~114 data points. Am I thinking about how InvokeRepeating() works correctly? Is my expectation with this setup even correct?

I suppose I could set tSample=10.0f and not give any inputs until 10 seconds have passed to essentially make it seem like the recording started at 0 seconds, but I really don’t like this approach as it seems like a cop out and a non programmatic solution to my problem.

I’m really open to any advice you guys may have and I really could use some help with this as this and some other issues have really stopped me in my tracks. Thanks in advance!

Ok it’s been a while, but I figure I should post my findings in case anybody ever has a similar problem. So InvokeRepeating does work the way I described above.

My issue was that I had declared tSample and interval as public variables. Apparently once a public variables initial value has been set during the scripts very first run, the only way to change those values is to use the Inspector. So the initial value for tSample was 10.0f and that’s why the script would always wait 10 seconds before recording data even though I had changed tSample to 0.0f in the script. It wasn’t until I manually changed its value through the inspector that the change took hold. Alternatively you could also make those variables private and then any changes made to those variables should take hold each time you run the script, as one would normally expect it to.

Thanks to hexagonius for recommending using the debug logs, they were very helpful! If anything here is incorrect please feel free to fix it or remove this answer, as I don’t want to mislead anyone.