Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Force re-run System in the same frame

Discussion in 'Project Tiny' started by reallyhexln, Apr 25, 2019.

  1. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Is it possible? Do you know any hacks to achieve that?
    I need to run UICanvasSystem while my system is working, to update actual canvas size and then immediately continue my code.
     
  2. Pakor

    Pakor

    Joined:
    Feb 2, 2017
    Posts:
    32
    You mean you want to return to the Update function at some point in code and then loop through again without returning a second time? Could you show an example of what exactly you want to achieve?
     
    reallyhexln likes this.
  3. Zionisias

    Zionisias

    Joined:
    Apr 23, 2019
    Posts:
    40
    I guess you could divide your system into two systems. Then you can run your first system (which contains first half of your code) then run the UICanvasSystem, and then run your second system (which contains the second half of your code). This would require you to store the data used in the first system however, if you have any, to be used in the second system.
     
    reallyhexln likes this.
  4. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Pakor, yes, you're right.

    I have System A that doing two things:

    1) It determines current aspect ratio of the screen and aspect ratio of Canvas. If we have screenAspectRatio > canvasAspectRatio, it sets
    canvas.matchWidthOrHeight to 1, otherwise it sets canvas.matchWidthOrHeight to 0.
    So, I want to achieve the behavior of Canvas like it works in Unity3d.

    2) Second, it fills the empty space between screen and Canvas content with some sprite. Unfortunately, I can't get an actual size of Canvas on this step, because it should be recalculated after the previous step applied.

    So, I want to run first step, then run UICanvasSystem (to update Canvas real size), then run second step.

    Currently, I use a workaround to achive such behavior:

    1) I do step 1.
    2) I do step 2 but I assume the size of image is half of Canvas (it's a value that enough to fill entire space almost in all cases).
    3) I wait for next frame.
    4) I do step 2 for the updated size of Canvas

    Also, I have added
    Code (JavaScript):
    1. @ut.executeAfter(ut.Shared.UserCodeEnd)
    2. @ut.executeBefore(ut.Shared.PlatformRenderingFence)
    to my system, but I'm not sure there is a sense.

    Zionisias, I agree, it may be a good decision. But how can I run UICanvasSystem from my code?
    I try to call it from current scheduler:
    Code (JavaScript):
    1. this.scheduler.schedule(ut.UILayout.UICanvasSystem);
    but it looks like it's not working. I get the following assertion while executing such code:
    Code (JavaScript):
    1. Uncaught abort("Assertion failed: !item.system, at: C:/Users/Abdul/Documents/tiny/Runtime/modules/core/src/Scheduler.cpp,51,"). Build with -s ASSERTIONS=1 for more info.
    Sorry for my awful english.
     
  5. Zionisias

    Zionisias

    Joined:
    Apr 23, 2019
    Posts:
    40
    Scheduling systems is done by Unity Tiny itself, but you can indeed use executeAfter and executeBefore. For the solution I proposed, you should add the executeBefore to your first system:
    Code (CSharp):
    1. @ut.executeBefore(ut.UILayout.UICanvasSystem)
    2. export class ExampleSystem extends ut.ComponentSystem {
    And the executeAfter to your second system:
    Code (CSharp):
    1. @ut.executeAfter(ut.UILayout.UICanvasSystem)
    2. export class ExampleSystem2 extends ut.ComponentSystem {
    I can not 100% guarantee that this will work, but in theory it should.

    You could check the bottom part of the main.js file in your browser console under "sources", where all systems are scheduled. Search for your systems, and check if UICanvasSystem is scheduled in between the two.
     
    reallyhexln likes this.
  6. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Thank you very much, Zionisias.
    It works perfect.

    Also, special thanks for clue about order of systems in generated file. Now, some things become clear for me.
     
    Pakor and Zionisias like this.