Low Frame Rate - CPU Usage Way up

Options
I am spawning 25 objects. If I'm the one who spawned the objects everything is good.
If i'm someone who joined the room, my frame rate goes way down because the CPU is way up. This only effects the person who joined. (not the one with the objects).

I had no problem with this many objects (or more) with older versions of photon in my older games, but in my new game it's a big issue.

I took a screenshot of the Unity Profiler. It looks like PhotonTransformView.Update() is taking up 90% of the CPI. With it split 45%/45% on PhotonTransformView.UpdatePosition and PhotonTransformView.UpdateRotation

Screenshot of profiler here:
http://imgur.com/a/ORUYP

Please advise.

-Carmine

Comments

  • Hi,

    Can you expand on what's under UpdatePosition for example?

    And with the very same project and the same 25 objects spawned the same way at the same place in your level, you can see a difference between an old version of PUN and a new Version? If it is the case and you can share your project, can you email photon support and ask for me to look at it, I'll take over on the other side to replicate and find the cause.

    Bye,

    Jean
  • carmine
    Options
    jeanfabre said:

    Hi,

    Can you expand on what's under UpdatePosition for example?

    And with the very same project and the same 25 objects spawned the same way at the same place in your level, you can see a difference between an old version of PUN and a new Version? If it is the case and you can share your project, can you email photon support and ask for me to look at it, I'll take over on the other side to replicate and find the cause.

    Bye,

    Jean

    Sorry I wasn't clear... I have an existing game that works awesome. I've started a NEW game. I'm not upgrading the PUN (in my project) from an old one to a new one iI'm more making a statement that PUN (in general) did not have a problem with this many objects in the past. I was trying to avoid someone saying PUN can't handle that many objects (because it can). The objects in my new game are much simpler actually (it's very early in development)

    If I do a "deep profile" it looks like it's literally just updating local_position. Here is the expanded deep profile:

    https://imgur.com/a/D7ego

    Also, here is my view in Unity of one of the objects:
    https://imgur.com/a/rlWLN

    Thanks in advance for your assistance.
  • Hi,

    Ok, thanks for the clear explanation, it helps.

    That's very odd indeed, what's the Unity version? and what was the unity version on your project that works well?

    What I suspect is the following:

    if you synchronize both the transform and the rigidbody, I bet the physics engine is upset because you force the position of the transform that is actually a rigidbody, and so you should not do that as it impact performances in the physics engine itself.

    This is likely not noticeabl with few objects, but in your case this certainly adds up.

    So:, several things:

    -- I think that I raised a very good point actually, it never occurred to me before in this context . I'll talk about this internally, maybe I should make a new pass on this and provide MovePosition() and MoveRotation() to avoid upsetting the physics engine.

    -- On your end, to get this tested, I would skip the photonTransformView and build a custom one that uses MovePosition and MoveRotation which is compliant with the physics engine to move RigidBody around.

    -- Also, as a third potential source of debugging, If you are developing with the very latest version of PUN, we've introduced a fix for initial position drifts when player joins, this effectively means forcing the position when a object is instantiated for the first time, this wasn't there before, in your case this could be something to explore and disable to check if it improves the situation. In PhotonTransformView, in the OnEnable() method, comment m_firstTake = true and test if it performs better.

    Let me know how it goes, it's important that these components behaves properly and if indeed there is something fishy here, we need to address it.

    Thanks :)

    Bye,

    Jean
  • carmine
    Options
    Well, if
    jeanfabre said:

    Hi,
    -- I think that I raised a very good point actually, it never occurred to me before in this context . I'll talk about this internally, maybe I should make a new pass on this and provide MovePosition() and MoveRotation() to avoid upsetting the physics engine.

    -- On your end, to get this tested, I would skip the photonTransformView and build a custom one that uses MovePosition and MoveRotation which is compliant with the physics engine to move RigidBody around.

    -- Also, as a third potential source of debugging, If you are developing with the very latest version of PUN, we've introduced a fix for initial position drifts when player joins, this effectively means forcing the position when a object is instantiated for the first time, this wasn't there before, in your case this could be something to explore and disable to check if it improves the situation. In PhotonTransformView, in the OnEnable() method, comment m_firstTake = true and test if it performs better.

    Bye,

    Jean

    UPDATE:
    - Removing the transform view, does help the frame rate. HOWEVER. Now things aren't synchronized :(

    I'm not sure what you mean by MovePosition and MoveRotation. Is there a good solid documentation on using Photon with rigidbodies? Most of the demos seem to be for non-rigid or 2d.

    Thanks!

    -Carmine
  • Hi,

    MovePosition and MoveRotation are Unity api, sorry for not being clear on this:

    https://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html
    http://answers.unity3d.com/questions/215377/transformtranslate-vs-rigidbodymoveposition.html

    Usually, the default setup is fine, because it's highly recommended to not synchronized that many objects, it impacts performances quite a lot, that's maybe why we never caught this.

    In your case, and while we'll discuss this internally, you should create a new component that will replace PhotonTransformView, and experiment with what's the best option to keep track of your rigidbody position.

    Just to lift another potential misunderstanding, your previous project that works well is not using rigidbodies for networked gameobjects right?


    Bye,

    Jean
  • carmine
    Options
    jeanfabre said:

    Hi,


    Just to lift another potential misunderstanding, your previous project that works well is not using rigidbodies for networked gameobjects right?


    Bye,

    Jean

    My previous game does have rigidbodies and it's been like that for years. www.quintet.us (you can also find it on steam) I built it using Unity4. The photon version it has is from before there was this transformview and rigidbody view (back when we just used RPC and not PunRPC) and you had to write your own stuff. I've had up to 37 players in a room without any issue.

    To be honest, I've scoured message boards, reddit, etc. and I just (for years) could not find a great example/tutorial of Photon with rigidbodies. I always seem to find conflicting answers on what to do (or hit dead ends).

    Can you guys just make a rigidbody demo? It can be 1 scene, with a bunch of cubes that can fly around and that's it. (or let me know if there is one in the Demos folder?)

    Thanks!

  • jeanfabre
    jeanfabre mod
    edited September 2016
    Options
    hi,

    yep, following your experience, I think it's now important to have a test scene with heavy usage of rb.

    I see, Unity 4 had a very different Physics engine than Unity 5. It could also play a major role in the difference you are witnessing. I have personally had projects failing to move to Unity 5 because of this... This is something to consider too.

    Bye,

    Jean
  • carmine
    Options
    jeanfabre said:

    hi,

    yep, following your experience, I think it's now important to have a test scene with heavy usage of rb.

    I see, Unity 4 had a very different Physics engine than Unity 5. It could also play a major role in the difference you are witnessing. I have personally had projects failing to move to Unity 5 because of this... This is something to consider too.

    Bye,

    Jean

    - Any chance of Photon/ExitGames making a very basic "This is how you do network rigidbodies with photon" demo?

  • Hi,

    yes, maybe I wasn't clear in my last post. We'll try to come up with something indeed.

    Bye,

    Jean
  • jeanfabre
    Options
    Hi,

    It's odd I am not experiencing this in my attempt to reproduce, however I found that inside PhotonHandler.cs profiling is still happening, which leads to a question:

    All this is witnessed inside the editor. But have you profiled when published, do you experience also this issue?

    Bye,

    Jean
  • carmine
    Options
    jeanfabre said:

    Hi,

    It's odd I am not experiencing this in my attempt to reproduce, however I found that inside PhotonHandler.cs profiling is still happening, which leads to a question:

    All this is witnessed inside the editor. But have you profiled when published, do you experience also this issue?

    Bye,

    Jean

    Hello,
    This happened in builds and in the editor.

    Weeks ago I changed it to use the "void OnPhotonSerialize..." kind of thing (I forget the exact name) and it worked immediately better so I dropped trying to use your PhotonTransformView.

    -Carmine
  • jeanfabre
    Options
    Hi,

    Ok, I am glad you got a solution for this. I am still unsure about what's happening in your project that create this much trouble at start. If you can share your project, pm me, I can sign ndas, and this could lead me to the issue.

    Bye,

    Jean
  • Tobias
    Options
    @carmine: Which version of PUN are you using in the newer title?
    We updated performance a few times in the last releases but if your case shows a problem, we'd like to work on it.
    Can you post a screenshot of an unfolded performance graph, next time?
  • carmine
    Options
    Tobias said:

    @carmine: Which version of PUN are you using in the newer title?
    We updated performance a few times in the last releases but if your case shows a problem, we'd like to work on it.
    Can you post a screenshot of an unfolded performance graph, next time?

    Hey Tobias I posted the unfolded deep profile here:
    https://imgur.com/a/D7ego

    I was using the absolute most up to date PUN as of the date i posted this (Sep 29th).
    If I went to that code in the PUN is was a very short function that seemed to be just setting local position.

    If you have an updated PUN since Sep 29th, I could try again.
  • Tobias
    Options
    This looks like an issue in Unity, actually: "Transform.set_localPosition()" is in the Unity engine.
    I'm not sure if we can do anything other than report it as perf issue of Unity.
    We can try alternative APIs to set this but it sure looks like a bug.

    Are you using a beta Unity? Or anything that could explain the high cost?
    Could it be related to the efforts that Unity becomes more multithreaded and it's blocking cause the physics are locking the object? That's wild speculation.
  • carmine
    Options
    Tobias said:

    This looks like an issue in Unity, actually: "Transform.set_localPosition()" is in the Unity engine.
    I'm not sure if we can do anything other than report it as perf issue of Unity.
    We can try alternative APIs to set this but it sure looks like a bug.

    Are you using a beta Unity? Or anything that could explain the high cost?
    Could it be related to the efforts that Unity becomes more multithreaded and it's blocking cause the physics are locking the object? That's wild speculation.

    It's not a Unity beta. It's their current stable version.
  • neoneper
    neoneper
    edited February 2017
    Options
    Hi. I had this same problem using the most new version of PhotonServer with the MMO application.

    I spent many hours trying to figure out what the problem would be that was causing my FPS loss.

    Simulating different situations and using the advice of this topic I ended up making great discoveries that helped me a lot.

    The biggest villain in my project ended up being the CANVAS component.

    I, my game, each visible player has a CANVAS component in his Object. This Canvas component is responsible for displaying the player's name and also some other information.

    I have discovered that many canvas components simply will not work in Unity.

    Notice two following images.

    At this first picture my FPS with all Player Canvas activated.
    I have about 60 players visible at the moment.


    Now watch my second figure.
    The same objects are on the screen, but now I disable the Canvas component of each of them.


    It's really very unlikely! I was shocked.

    Another factor that made some difference in my testing was the use of Gravity enabled in the players' RigidBody component.

    I noticed that if I keep gravity off I get some free FPS.
    So I used creativity to develop in my scrip a logic that activates gravity only when the player is really far from the ground!

    I hope it can help future problems. (^.^)


    PS:
    I have not yet found a solution to the Canvas problem.

    Maybe I have to go back to using TexMesh. I'm not sure. But all my tests with multiple CANVAS are resulting in problems!
  • neoneper
    Options
    Unbelievably it seems the trick is not to mix dynamic UI elements with static UI elements in the same CANVAS. Of course using dozens of canvas also does not help. But the test with a single canvas rendering all the Dynamic elements and another only for the static, HUD example, solves the whole problem.
    https://support.unity3d.com/hc/en-us/articles/115000355466-Split-canvas-for-dynamic-objects
  • jeanfabre
    Options
    Hi,

    Very informative. Thanks for sharing.

    Bye,

    Jean
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited February 2017
    Options
    @neoneper @jeanfabre

    I highly recommend this talk.

    Question is:
    When to stop splitting? I want to know when too much is too much.
    There are multiple splitting options:

    Vertical:

    RootCanvas
    - ParentCanvas1
    - - ChildCanvasA
    - - ChildCanvasB

    Horizontal:

    RootCanvas1
    RootCanvas2

    There is also CanvasGroup.

    If we can continue the discussion here that would be great! I have a game 100% built using Unity UI and I'm interested to know any trick to optimize it.