On Responsive Container, Resize() is public and can be called at any time. If it is called when the object is not active in hierarchy, there seems to be some strange issues. I sometimes see NaN values, and things do not resize properly.

I have had some success by preventing Resize() as follows:

// Do not allow Resize if not active since object sizes may not be correct, unless in editor.
if (Application.isPlaying && !gameObject.activeInHierarchy)
    return;

But I still run into issues where the size is wrong when the object does become active.

I'm thinking for the public Resize() you need to check if active and if not, set a value so that when the object does become visible it will then call a private Resize().

I have also found that sometimes you need to wait an update or two before Resize() will get updated with correct sizes. This is especially noticeable on containers set to OnChange. So I'm thinking that maybe in these cases you let update run for 3 to 5 (or some config value) times that way it properly adjusts to other related objects as they also change.

    dtappe Thanks for reporting, the UI on Unity side needs a few frames to update in cascade, calling multiple time the Update() method should not solve this, have you tried?

      Sorry, I did not mean that Update() should be called multiple time. I meant that when OnChange is used, that it should allow the Resize() to be called for multiple frames, not just one frame. [EDIT: REMOVE: I did try something but did not get the results I was looking for].

      EDIT:

      I did try it and I think it is working. I also needed to make sure that the first time an object becomes visible it is forced to be seen as a change. I used 10 frames at Start() and also when Resize() is called manually from outside of Responsive UI, and the object is not active in hierarchy, but applied when the object later becomes active. That seems to get the objects to size correctly.

      I think this original post is still something that should be looked at, but I now believe that my underlying problem is actually related to having a Vertical/Horizontal layout group that changes sizes of children as a parent of a Responsive Container hierarchy. I get really strange behavior and different results depending upon if I am running in editor or running standalone build. Also, sometimes the issue seems to be fixed, until I close Unity and restart it, then the issue comes back. I definitely see NaN when things are messed up. This may need to a different issue. I am in the process of trying to remove the layout groups and switch to use Responsive components.

        dtappe thanks for the solution feedback, I will definitely add this. For the NaN errors, I had them as well so time, couldn't find the issue yet. Thanks for your help, I really appreciate!

          Write a Reply...