Search Unity

Discussion Can you interpret this result for me

Discussion in 'Scripting' started by StarBornMoonBeam, May 4, 2023.

  1. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    Code (CSharp):
    1.  
    2.  for (int i = 0; i < PARTICLE_NUMBER; i++)
    3.       {
    4.           X = PARTICLES[i].x + Random.Range(MOVE_DIRECTION.x, MOVE_DIRECTION_MAX.x);
    5.           Y = PARTICLES[i].y + Random.Range(MOVE_DIRECTION.y, MOVE_DIRECTION_MAX.y);
    6.            if (Y < -280)
    7.             Y = 280;
    8.            if (X < -500)
    9.             X = 500;
    10.            PARTICLES[i] = new Rect(X, Y, RECT_SIZE.x, RECT_SIZE.y);
    11.         }
    12.  
    egz.gif
    20fps gif.

    new particles never spawn they just recycle on the screen when below point as the code says. But they pop up from zero, center screen. I know as far as center screen is 0,0 but at no point do they come back up near center yet you can see that they do.

    gf3.gif
     
    Last edited: May 4, 2023
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,999
    Is it possible that you have multiple cameras in your scene? It's really hard to tell since we don't even know what kind of particles you're talking about. Since you only check for the negative border in X and Y we would assume that the particles always move in the negative direction? So your "MOVE_DIRECTION" and "MOVE_DIRECTION_MAX" are both negative? If not your code doesn't make much sense. However if the particles always move towards the diagonal negative (bottom left), those that actually move to the top left may just be the same particles just viewed with a second camera from a different point.
     
    StarBornMoonBeam likes this.
  3. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    Sorry for the hard question.

    No second camera in the scene.

    It is in the editor though. So I wonder maybe if some misunderstanding is happening between screen sizes. I put some values in there that corresponded to approximately editor sized. But the actual res I was on is 1280 720 It's suppose to give me the canvas from 0 bottom left I believe with those values, and then I could use that for the lowest point reference. But yeah I don't know either lol but I didn't want to stay up all night tonight working with it. I think it might be editor window aspect related.
     
  4. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    They even clip from the point of the screen as if the aspect had sliced them off like you say as if a second camera is watching.
     
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,999
    Are you sure about that? Cameras could have hideflags set so they don't show up in the hierarchy. You could try my ancient hidden object browser script I posted over here. I'm not sure if this script still works. A lot has changed in the past 9 years ^^.

    Note that there may be hidden objects which belong to the sceneview(s) or other internal stuff. Though it's worth a shot. Maybe you have some faulty editor code somewhere that has left a camera in the scene?
     
  6. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    cams.gif

    So looks like you don't need a camera for that type of rendering
    look how weird it is.
    the left edge of the screen still acts as if a display camera is rendering, while the main screen is set to don't clear. I messed with aspect ratio closed scene view, but hm. no success i am using Graphics DrawTexture

    horitztonal.gif


    aspect2.gif
     
    Last edited: May 5, 2023
  7. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,999
    Why haven't you said that right in your first post? You talked about particles so everyone would assume you use Unity's ParticleSystem.

    When you draw stuff manually it highly depends on where and when you draw stuff. You CAN NOT use those low level rendering methods in Update. Update executes way too early. With other callbacks like OnGUI for example you have to be careful at which event you're rendering. As the documentation of Graphics.DrawTexture even warns about you must only draw during the Repaint event.

    However at the moment we have no idea what you're actually doing. The snippets of code you have shown doesn't seem to be related to your problem at all.

    What "type of rendering" are you even talking about? You really should explain your setup in more details. Using low level rendering requires a lot care and knowledge about how the GL rendering context in Unity works. You can not just "render" something at will. There are many factors to account for. So if you expect any further help, you really need to be more precise on what you're actually doing. Show your "rendering code". Though not just the rendering code, also where or from where it is called.
     
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,178
    Use a particle system. Unity's low level APIs just add unnecessary complexity.
     
    Bunny83 likes this.
  9. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    I don't like the solution but perhaps you are right

    Actually for now I disabled it

    But, I think it won't be that way in build so it may be build only test effect hold up il test
    ....


    Yes so the anomalous dual screen GUI position is present after build aswell

    Il explore more
     
  10. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    Code (CSharp):
    1. private void OnGUI()
    2.     {
    3.         if (Event.current.type.Equals(EventType.Repaint)) // THis is Important!
    4.         {
    5.             for (int i = 0; i < PARTICLES.Count; i++)
    6.             {
    7.                 Graphics.DrawTexture(PARTICLES[i], PARTICLE);
    8.             }
    9.         }
    10.     }
    I got it.

    So the smaller aspect is the correct one :) the larger (correct result looking one) was the bug !!
    Thanks girls. I hope we all learn the best way to make particle effect O_O

    fin.gif

    as you can see the smaller aspect now takes 0 to screen width and height for correct pix position
     
    Last edited: May 5, 2023
  11. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    2048 particles.gif

    Code (CSharp):
    1.  
    2.         Rect R = new Rect(0,0,0,0);
    3.         float X = 0;
    4.         float Y = 0;
    5.         var R1 = Random.Range(MOVE_DIRECTION.x, MOVE_DIRECTION_MAX.x);
    6.         var R2 = Random.Range(MOVE_DIRECTION.y, MOVE_DIRECTION_MAX.y);
    7.         var W = Screen.width;
    8.         var H = Screen.height;
    9.         Rect P;
    10.         for (int i = 0; i < PARTICLE_NUMBER; i++)
    11.         {
    12.             P = PARTICLES[i];
    13.              X = P.x + R1;
    14.              Y = P.y + R2;
    15.             if (X < 0)
    16.                 X = W;
    17.             if (Y < 0)
    18.                 Y = H;
    19.             R = P;
    20.             R.x = X;
    21.             R.y = Y;
    22.             PARTICLES[i] = R;
    23.         }
    2048 particles around 150% more than needed, without lights OnGui render not so bad.

    ezgif-2-b8939ba3a2.gif
    happy days
     
    Last edited: May 5, 2023