Search Unity

OnTargetObjectWarped gc allocations

Discussion in 'Cinemachine' started by iamarugin, Jan 6, 2019.

  1. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    110
    Cinemachine v2.2.8
    Every time I call OnTargetObjectWarped it generates garbage. Due to nature of my game I need to call it every frame. Are this allocations necessary? If it is only because of

    Code (CSharp):
    1. var extensions = GetComponents<CinemachineExtension>()
    in the CinemachineVirtualCameraBase, may be it would be better to use non alloc version? Like:

    Code (CSharp):
    1.  
    2. GetComponents<CinemachineExtension>(extensions);
    3.  
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    Yes, the implementation can be improved. Thanks for noticing that, we will fix it.

    However, warping the target every frame is not an intended use-case, and sounds like a strange thing to be doing. Can you describe the situation a little more, and explain what you're trying to do?
     
  3. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    110
    I have a 3d map of solar system with the orbiting planets and satellites (like in KSP) and cm freelook camera. Player can select any planet and rotate camera around it. Also the whole system is moving in real time and I have a time warp feature with the ability to increase the speed of time up to x100k. Every frame I calculate the new positions of all celestial bodies and warp them to the calculated positions. Even with the 1000x time speed and the scale 1/120000 the warping distances are huge, but I want the camera to remain still relative to its target, as if there is no motion at all. OnTargetObjectWarped worked well for this so far, but yes, I'm not sure if it is the right way to implement this behaviuor.

    Also I have a floating origin system and I rescale and reposition all objects in the solar system on camera zoom in/out, where I use this method too.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    Why not just have your vcam procedurally follow its target in a fixed relationship to it? Use transposer with Lock to Target binding mode. Then you won't need to warp anything. Except maybe when zooming.
     
  5. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    110
    Thank you, I will try to dig in this direction.
     
    Last edited: Jan 8, 2019