Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by wedermarco · May 15, 2020 at 02:43 PM · loopwebcamtextureframewebcamwhile-loop

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;
     }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Pangamini · May 15, 2020 at 03:05 PM 0
Share

What's wrong with coroutines?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wedermarco · May 15, 2020 at 02:58 PM 0
Share

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?

avatar image OnEd0t wedermarco · May 15, 2020 at 03:21 PM 0
Share

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.

avatar image wedermarco OnEd0t · May 15, 2020 at 05:44 PM 0
Share

It was pretty laggy but I could solve it by using coroutines. Thanks for the help :)

Show more comments
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Webcamtexture at 1080p 50fps produces black image 1 Answer

WebCamTexture.device on the Kindle Fire returning a camera 1 Answer

Chroma effect- revoke background from Webcam(Only my head) and put other backgrounds instead 0 Answers

WebCamTexture camera not activating 0 Answers

webcam Capture from webcam encountered: IndexOutOfRangeException: Array index is out of range 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges