Search Unity

  1. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice

Kinematica - Way to disable / enable in runtime?

Discussion in 'Animation Previews' started by Mic_Emond, Nov 9, 2020.

  1. Mic_Emond

    Mic_Emond

    Joined:
    Nov 16, 2016
    Posts:
    20
    Hi!
    I'm trying to optimise our way of working with Kinematica, especially for AI.
    I'd like to turn the Kinematica component off when AI are a certain distance from the player, potentially switching to a lighter animation system since Kinematica is pretty heavy.

    But it seems that isn't supported, it's throwing errors and characters aren't animated.
    I'd also like to be able to add the Kinematica component at runtime, but that also results in errors.

    Any way around this? Any plans to support it ?

    Thanks!
     
    Last edited: Nov 9, 2020
  2. FrancoisFournel

    FrancoisFournel

    Unity Technologies

    Joined:
    Feb 12, 2020
    Posts:
    64
    Hello,

    There is currently no way to pause Kinematica. However the costly part of Kinematica is actually mostly done in the client Job making the motion matching queries, so you can simply not run this job when you want to disable Kinematica. Kinematica own job will continue to run, but it will just advance time and read the corresponding pose from the library which is a pretty cheap operation.

    Example for Biped.cs from Biped sample :
    Code (CSharp):
    1.        
    2.  
    3. public bool enableKinematica = true;
    4.  
    5.         void Update()
    6.         {
    7.             if (!enableKinematica)
    8.             {
    9.                 return;
    10.             }
    11.  
    12.             float desiredSpeed = moveIntensity * desiredLinearSpeed;
    13.  
    14.             TrajectoryPrediction.CreateFromDirection(ref kinematica.Synthesizer.Ref,
    15.                 movementDirection,
    16.                 desiredSpeed,
    17.                 trajectory,
    18.                 velocityPercentage,
    19.                 forwardPercentage).Generate();
    20.  
    21.             KinematicaJob job = new KinematicaJob()
    22.             {
    23.                 synthesizer = kinematica.Synthesizer,
    24.                 idleCandidates = idleCandidates,
    25.                 locomotionCandidates = locomotionCandidates,
    26.                 trajectory = trajectory,
    27.                 idle = moveIntensity == 0.0f
    28.             };
    29.  
    30.             kinematica.AddJobDependency(job.Schedule());
    31.         }
    If you set
    enableKinematica
    to false, queries won't be executed
     
  3. Mic_Emond

    Mic_Emond

    Joined:
    Nov 16, 2016
    Posts:
    20
    Hey! Thanks for the solution.

    Although is there any plans to support enabling / disabling in the future?
    I'd really like to be able to disable the whole gameobject (for level streaming and other things), but it results in the same kind of errors sadly.

    I can work with this in the meantime though! But it would be nice to know if something else is coming in regards to this, as it seems it will prevent many things, such as pooling, dynamic loading of assets, etc.
     
  4. FrancoisFournel

    FrancoisFournel

    Unity Technologies

    Joined:
    Feb 12, 2020
    Posts:
    64
    Yes you're right, we will support easy enabling/disabling of Snapshot debugger & Kinematica in the future !
     
    simonaaitor and Mic_Emond like this.
  5. Mic_Emond

    Mic_Emond

    Joined:
    Nov 16, 2016
    Posts:
    20
    Great news! Thanks!
     
  6. antidirep

    antidirep

    Joined:
    Oct 5, 2018
    Posts:
    4
    Awesome this helped me a ton. I was scratching my head about this as well. I would also like to disable and re-enable gameObject with Kinematica without throwing an assertion exception.
    Can't wait!
     
  7. simonaaitor

    simonaaitor

    Joined:
    Sep 8, 2020
    Posts:
    11
    Wow, I was about to post exactly this same problem, great to know it's on the list!
     
unityunity