Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 habsi70 · May 14, 2016 at 09:59 AM · buildsevent-handlingexecution-order

Objects flashing for one frame after building for Windows

In our current project we are using a 3D book (MegaBook) which can be paged by touch/drag. I work on a 2013 Macbook Pro. When opening the front cover I also move the book smoothly a little to the left while dragging the page. Everything works fine until a do a build for Windows.

After the build the book moves for one frame to its end position resulting in a flashing object when I start a drag event. This is the case in the Windows build and in play mode!

The wrong position is due to a logic error in my script handling the touch-down event. The position resets for in a line before the correct position is set again when the touch down event is triggered.

What is troubling is Unitys unpredictable behaviour. When I start/restart Unity the scene in play mode works as expected, after doing another build the problem is there again. BUT: not always!! Sometimes the build and the play mode work as I expect. This makes it very hard to debug, it took me a long time to find out what the errors was. I do not use any threads.

In the same script I call a function while dragging. I return if a flag is not set. Yet I have to check the flag in the same function again because the value might have changed.

 void OnDragging(DragInfo draginfo)
     {
         if (!isPaging) return; // only execute when flag is set
 
         ray = camera.ScreenPointToRay(draginfo.pos);
         Vector3 currentPos;
 
         if (Physics.Raycast(ray, out hit, 1000f, touchLayerMask))
         {
             currentPos = hit.point;
         }
         else return;
 
         // hasPagedAfterTouch = true;
         float newPagePos;
         canStopPaging = true;
         // page forward
         if (turnDir == 1)
         {
             // if current position is smaller than startPos compute newPagePos
             if (currentPos.x < startPos.x)
             {
                 ..... Calculate new page
         }
         // page back
         else if (turnDir == -1)
         {
             ..... Calculate new Page
         }
                 // Sometimes isPaging changed while function is executed
         if (isPaging && hasPagedAfterTouch)
         {
             currentBook.SetPage(TranslateBookPage(nextPage), true);
         }
     }


Why does Unity sometimes draw the wrong position, sometimes it does not? Are functions called by events interrupted (threading?) and the frames drawn before the function is continued? I always assumed that a function is executed in one go.

Comment
Add comment · Show 4
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 meat5000 ♦ · May 14, 2016 at 10:45 AM 0
Share

Unity never draws the wrong position. Only what you give it.

If you want a function to defer execution you must use a coroutine.

If you move an object and on the next line move it back you should not see this movement as it was executed within one frame and does not get the chance to Update in between.

https://www.google.co.uk/search?q=unity+code+stepping&ie=utf-8&oe=utf-8&client=ubuntu&channel=fs&gfe_rd=cr&ei=-_o2V5HmDsSFaNrOlcgB&gws_rd=ssl

Use stepping and breakpoints to help find the problem. Debug.Log can also assist greatly in this.

avatar image habsi70 · May 14, 2016 at 11:04 AM 0
Share

Thank you for your input. I am aware that unity does not draw false positions if I do not set it that way. I mentioned in my question that it was mistake i had in my logic. The problem is that unity does under (at least for me) unpredictable circumstances draw the error, sometimes it does not.

The code is unchanged, but when the false position (set by me, I am aware) will only render after I do a build. That is puzzling.

By using Logging and other Debugging Tools I could confirm that I made an error, but the error shows only after doing a build. And even then it does not in all cases.

avatar image meat5000 ♦ habsi70 · May 14, 2016 at 03:17 PM 0
Share

In this case, you should analyse the Branching. i.e the logic/conditions. You are right; it is hard to diagnose errors/bugs where conditional branching is involved (if else etc).

Use Block comments /* */ to remove chunks of code in the script until you are left with the bare bones, filling in some temporary dummy variables where things are required in order to do other functions. Otherwise Code-stepping is going to be your best friend.

avatar image habsi70 meat5000 ♦ · May 14, 2016 at 06:08 PM 0
Share

Thanks you for taking time to answer! The problem is, I know I made an error and where it is. The error is always there, confirmed by logging and Reflecting the value in a debug tool.

But unity draws the wrongly set position when a value within a currently executed function changes for a line and is set to the correct value a few lines down. It does this only after compiling a build. Then the flickering object is drawn in the build and in play mode. After a fresh start of Unity the error does not show anymore. The error is always there, I found it by exactly the practices you mentioned. Only it does not always render.

To rephrase my question: does Unity step out of a currently executing function to draw a frame?

0 Replies

· Add your reply
  • Sort: 

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

42 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

Related Questions

Fire an event when gameObject has been renamed? 2 Answers

IPointer Events don't seem to be working 3 Answers

Load xml from resource folder after build(web player) 0 Answers

huge iOS build size even with empty scene 0 Answers

Subsequent builds getting smaller.,Subsequent builds taking less space? 1 Answer


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