GC Collect When OnControllerColliderHit Called

This isn't related to Behavior Designer so the best that you can do is report it to Unity.
 
The issue is behavior registered the OnControllerColliderHit method

MyTest is 30 Object with behavior tree

1579142135528.png

the profile is Collect 2.3k GC pre frame
1579142287501.png

30 Object without behavior tree the profile is

1579142539790.png

There none of GC

Code:
public class MoveTest : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        GetComponent<CharacterController>().Move(Vector3.down * Time.deltaTime);
    }
}

In our project we dont need OnControllerColliderHit method , and performance is very importent in mobile, and gc is disgusting。
I need your help
 
You should really start getting in the habit of caching your components in variables. Everytime you declare GetComponent(), the engine has to perform intensive work to get the component. That's why many developers will store the component in a variable. Here's an example.

C#:
public class MoveTest : MonoBehaviour
{
    CharacterController m_Controller = null;
    
    // Start is called before the first frame update
    void Start()
    {
        m_Controller = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
        m_Controller.Move(Vector3.down * Time.deltaTime);
    }
}

Because the engine has to constantly fetch the component, all the previous component references are collected by the c# garbage collector. This can be quite taxing on hardware, and cause microstutters and framerate drops.
 
You should really start getting in the habit of caching your components in variables. Everytime you declare GetComponent(), the engine has to perform intensive work to get the component. That's why many developers will store the component in a variable. Here's an example.

C#:
public class MoveTest : MonoBehaviour
{
    CharacterController m_Controller = null;
   
    // Start is called before the first frame update
    void Start()
    {
        m_Controller = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
        m_Controller.Move(Vector3.down * Time.deltaTime);
    }
}

Because the engine has to constantly fetch the component, all the previous component references are collected by the c# garbage collector. This can be quite taxing on hardware, and cause microstutters and framerate drops.


emm, my fault, my test shows the how gc generated with the OnControllerColliderHit of behavior registered, In our project, every components are be cached
 
I'm not sure where CharacterController.Move_Injected is coming from as this isn't created by Behavior Designer. I'd post on the Unity forums to see if any of the Unity devs can respond.
 
It only happens if you have a OnControllerColliderHit method declared (and then I assume only if there's a collision, but with gravity that will nearly always be the case), because Unity has to allocate the hit information and provide it to you. than gc generated.
Can you provide me a dll that OnControllerColliderHit not declared? that will helpful
 
Last edited:
Where is CharacterController.Move_Injected being called from? It looks like that is the source of all of the allocations. You can download the runtime source on this page:
 
Top