Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Questions about performance

Discussion in 'Editor & General Support' started by Follet, Jan 21, 2022.

  1. Follet

    Follet

    Joined:
    May 18, 2018
    Posts:
    38
    Hello, I have multiple specific questions, if you could answer in only one I would be very grateful.

    - How much differece there is having 1 gameobject with a mesh with 20k tris and one material VS 10 gameobjects with a 2K tris mesh and one material for all (without occlusion culling)?

    - A deactivated gameobject, with a lot of meshes inside, does it cost performance if it's inside the player, while that player is always rotating and moving (not the said meshes inside moving independently)? Should that object be outside the player gameobject, then once active set it as child of player (moving to it's rotation/position)?

    - Does the canvas get "Dirty" when a button is pressed, if the UI inside dosen't change it's values?

    - A shader that is not dynamic (dosen't change values over time or by anything), is calculated on every frame or only once at start? (I ask to know if I can use shaders as normal materials or should I create textures with the same visual effect)

    - In C# how costly it is to get/call references and methods from other scripts? If a class is referenced, then doing something like "otherClass.GetPlayerSpeed"- And the same thing but extended "otherClass.PlayerControlerClass.PlayerRigidbody.velocity" or even more extended...?

    - in code, is it better to always set a variable in the update or check if a bool is true?

    float value = 0;

    update
    {
    value= 100;
    }



    or


    float value = 0;
    bool check = false;

    update
    {
    if(!check)
    {
    value= 100;
    check = false;
    }
    }



    Thanks in advance
     
    Last edited: Jan 21, 2022
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,003
    What do you mean without culling? Also are all the gameobjects in both cases static?

    Less gameobjects will always be faster, if it's faster enough to matter depends on many variables though and is case specific.
    A shader is always calculated every frame for every vertex and every pixel. The question to answer here is: Are the calculations I'm doing faster than a texture fetch? The answer here depends a lot on what kind of calculations you are doing and also the target hardware.
    Do you mean "moving" because the parent is moving, or are you also doing stuff to its transforms via script independent of the parent?
    I guess it depends on how often check is true, because in one case you are setting a float, on the other hand if check is always true, you are checking a bool and setting a float.

    BUT.

    This is the kind of micro optimization that really doesn't matter and you shouldn't really bother with.

    Personally, I would add a bool check, but not because of performance, but mostly because I know I would probably add more stuff in that case, so created a bool check designates a place to add that stuff.
     
    Follet likes this.
  3. Follet

    Follet

    Joined:
    May 18, 2018
    Posts:
    38
    Yes, both are static. In my case I want this info to use it in for my map objects. Without culling I mean that due to the nature of my game, the camera Occlusion culling will almost never hide objects behind others, so all of them are rendered. My game currently is using 4 gameobjects with ~12k tris each for the map, I wonder if dividing each part into minor ones (many or few like *3-6 objects/meshes each part) to do things with those would have an impact.

    Thanks, that answers my question. I use a wireframe view ingame, and currently using a shader that does that for everything. In my case I guess replacing that shader for materials/textures would be better. Thanks! (also target is android)

    I mean the Player (that is the parent) moves around the map. The other object full of gameobjects/meshes should or not be inside the player while is deactivated?

    Thanks, if the difference is minimum I will not worry about it. I asked because that case happens or/and can happen a lot in my project. Will do one or the other based on things not related to performance.

    Thanks a lot @AcidArrow for taking the time to answer
     
    Last edited: Jan 21, 2022