Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 JonBonne · Feb 12, 2015 at 04:56 AM · graphicsvsyncdrawmesh

How to draw a mesh for a single frame with vsync disabled?

I have a mesh for drawing bullet trails as a line. The bullets travel instantly, so I just want to draw it for a single frame. If the line is visible for too long, and the player is moving while firing, the gun will move away from the line and it will be left floating in space, which looks bad. I don't want to move the line with the gun, I need the line to only be visible while it is in the same location as the gun barrel.

This is what I have:

     int renderCount = 0;
 
     void OnRenderObject()
     {
         if (renderCount < 1)
         {
             Graphics.DrawMesh(mesh, matrix, material, 0);
         }
 
         renderCount++;
     }

This works with vsync enabled. With vsync off, the line is only occasionally visible. I assume this is because the scene is being rendered multiple times before being displayed on the screen. Even using if (renderCount < 5) does not show the line consistently.

Am I correct? Is there a solution? Is there a way to know when something has actually been rendered?

Comment
Add comment · Show 14
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 incorrect · Feb 12, 2015 at 04:59 AM 0
Share

I guess it's because VSync reduces framerate, so you have a chance to notice your bullet trail, while with VSync switched off you don't have a chance, it's too fast. :)

avatar image incorrect · Feb 12, 2015 at 05:01 AM 1
Share

Why don't you draw it for a fixed amount of time ins$$anonymous$$d of number of frames? It's awful to make framerate-dependent code!

avatar image JonBonne · Feb 12, 2015 at 05:47 AM 0
Share

I don't know how long I need to draw it for unless I make it depend on the frame rate. I need to draw it for the $$anonymous$$imum time possible. How would I do that?

avatar image Eric5h5 · Feb 12, 2015 at 06:46 AM 1
Share

The only way something would last .25 seconds at a $$anonymous$$imum is if your framerate was 4fps, or your logic was incorrect. All you have to do is wait for the desired amount of time, say .05 seconds (1/20th). Coroutines or Invoke are generally easier for this sort of thing than Update.

avatar image Eric5h5 · Feb 12, 2015 at 07:49 AM 1
Share

You need to turn on vsync. Also Invoke is not necessarily synced to the framerate...just attach this to an object, and hit space:

 function Update () {
     if (renderer.enabled) {
         renderer.enabled = false;
     }
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space)) {
         renderer.enabled = true;
     }
 }

This is easily visible and anyone can see it 100% of the time; 1/60th of a second is a relatively long time when it comes to vision. Again, vsync is required, or else the effect can disappear "between" frames.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Feb 12, 2015 at 07:23 AM

I think what you need is the exact moment, a frame was renderer to the screen. This could help render as long as this Unity message is called, then stop

MonoBehaviour.OnPostRender

Just read the documentation here Graphics.DrawMesh and it seems that it should definitely draw it for one frame. You might want to file a bug report (under Unity -> Help -> Report a bug) on the docs.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Will this script that does drawmeshinstancedprocedural actually work? 0 Answers

Graphics.DrawMeshNow on top of gui elements 1 Answer

Graphics.DrawMesh not working 2 Answers

Using Graphics.DrawMeshNow() in the Repaint event of an OnGUI function of an EditorWindow with custom projection matrix 1 Answer

Populate people in city with DrawMeshInstancedIndirect? 2 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