Kinematica - Way to disable / enable in runtime?

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!

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 :

public bool enableKinematica = true;

        void Update()
        {
            if (!enableKinematica)
            {
                return;
            }

            float desiredSpeed = moveIntensity * desiredLinearSpeed;

            TrajectoryPrediction.CreateFromDirection(ref kinematica.Synthesizer.Ref,
                movementDirection,
                desiredSpeed,
                trajectory,
                velocityPercentage,
                forwardPercentage).Generate();

            KinematicaJob job = new KinematicaJob()
            {
                synthesizer = kinematica.Synthesizer,
                idleCandidates = idleCandidates,
                locomotionCandidates = locomotionCandidates,
                trajectory = trajectory,
                idle = moveIntensity == 0.0f
            };

            kinematica.AddJobDependency(job.Schedule());
        }

If you set enableKinematica to false, queries won’t be executed

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.

Yes you’re right, we will support easy enabling/disabling of Snapshot debugger & Kinematica in the future !

2 Likes

Great news! Thanks!

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!

Wow, I was about to post exactly this same problem, great to know it’s on the list!