- Home /
 
Is it possible to call a method once per frame inside of another method?
I'm working with live video processing.
My problem is that I want to call a method and inside this method I want to have a loop that runs every frame just like Update() but after a defined time I want to break the loop and return something.
I know that there is a while loop but as far as I know, this loop does everything in just one frame and that's not quite what I'm searching for.
Does anybody have a solution? I added a small example (not real code) to clarify what I mean.
 public void DetectFace()
     {
         int detectedFaces = 0;
         Vector2 nosePos;
 
         //loop that calls once a frame, I used while for demonstration
         while (detectedFaces < 10)
             if (FindFace())
             {
                 detectedFaces++;
                 nosePos = GetNosePos();
             }
             else
             {
                 detectedFaces = 0;
             }
 
         return nosePos;
     }
 
              Answer by OnEd0t · May 15, 2020 at 02:50 PM
You can use Invoke() to invoke a method after a cerain time that you specify.
hmm in unity there is a method like: WebCamTexture.didUpdateThisFrame and I have to be able to check if the webcam got updated. Would you suggets Invoke() like every 0.05 seconds and check if its a new frame? 
might be taxing on the hardware but sure try it and see if it suits your needs. although I haven't personally had to use something like`WebCamTexture.didUpdateThisFrame` before, so i don't know what impact on performance it does.
It was pretty laggy but I could solve it by using coroutines. Thanks for the help :)
Answer by tadadosi · May 15, 2020 at 05:56 PM
Why not just use a public bool to disable it? it could be inside a for loop in Update or maybe a coroutine with a while loop using that bool as condition.
Your answer
 
             Follow this Question
Related Questions
how to check if webcam is used by another application 0 Answers
Projector with WebCamTexture as texture 0 Answers
How do I enable the Android lock screen in developer mode? 1 Answer
WebCamTexture IOS crashing? 1 Answer
Do-While loop 2 Answers