• 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 a67_nk · Aug 18, 2018 at 10:41 AM · uipanellatency

UI latency and panel loading issues

I have a project that encrypts a given file, you have to fill in the required details and then a screen should pop up that displays the percentage of file encrypted. The issue is when I click the encrypt button everything freezes the screen pops up after the encryption is complete showing the encryption complete message this is noticeable when I try to encrypt larger files.

In my code I first activate the panel and then I have called the function that encrypts the file, still it freezes until the encryption is complete and then the "encryption complete" message on the panel pops up.

 ciphDescPanel.SetActive(false);
 encryptionPanel.SetActive(true); //this panel should show when "encrypt" button is clicked, but it shows when the functions(cipherCallBacks.__CIPHER() ) called below complete their execution.
 string empty = "_EMPTY";
 
 if (encryptionPanel.activeInHierarchy == true) {
         if (passwordPin.isOn)
             cipherCallBacks.__CIPHER (filePathString, cipherFileDirString, paPiEntryString, empty, keyLength); //function to encrypt file
         else if (key.isOn)
             cipherCallBacks.__CIPHER (filePathString, cipherFileDirString, empty, keyFilePathString, keyLength); //function to encrypt file

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gvergidis · Aug 21, 2018 at 11:30 AM

Well, that is why C# is serial programming and not parallel. Imagine the code as a road. A car follows a car and so on. If a car stops, all cars behind it must stop to and wait until the car continues. It is the same thing but we have to deal with data.

What you need to do, is try using a coroutine. Coroutine is like adding a parallel road for more cars to pass the same time with others.

Consider the following example :

 public void DoSomeLargeMaths()
     {
         Debug.Log("Started calcualting. This may take some time. Buhaha...");
         for (int foo = 0; foo < 99999999; foo++)
         {
             float x = Mathf.Pow(2f, 5f);
             float y = Mathf.Pow(3f, 9f);
             float z = x + y;
         }
         Debug.Log("Finished. Are you still alive?");
     }

This calculation will take soooo much time to finish and all other operations after that will halt until this calculation is finished. Now, consider this :

 public IEnumerator DoSomeLargeMaths()
     {
         Debug.Log("Started calcualting. This may take some time. Buhaha...");
         for (int foo = 0; foo < 99999999; foo++)
         {
             float x = Mathf.Pow(2f, 5f);
             float y = Mathf.Pow(3f, 9f);
             float z = x + y;
 
             yield return null;
         }
         Debug.Log("Finished. Was that long?");
     }


This function will do a calculation and halt every frame so it does not halts others operations. This will keep calculating simultaneously with other operations (showing progress etc.).

Remember that this function is called like that :

 StartCoroutine(DoSomeLargeMaths());

Calling it as a simple function will bring the same results as not using coroutines.

I hope I helped.

  • yield return null orders programming to wait for a frame and the return there.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

150 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 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

How to adjust the screen resolution? 0 Answers

Canvas, Scroll Rect, Panels, Panes? 0 Answers

Drop down style info panel 0 Answers

ui panel disappears after showing for few seconds ?(problem) 1 Answer

rendering panel w/children 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges