Friction not being disabled on 0

Hello,
I am attempting to disable the friction for specific physical ECS entities, because I handle the friction calculation in my own system.

I am using the samples provided from the Unity.Physics package to set PhysicsShape and PhysicsBody and control the friction there, however it doesn’t appear the friction is fully disabled. Even after inspecting given entity in Runtime mode, the friction is correctly set to 0.

I did a quick experiment, where I set the friction to 0 and applied force onto the object. With 0 friction, it should move indefinitely, however it still stopped after a couple meters, meaning some friction is still applied.
The amount of friction is affected by the Friction value, but 0 doesn’t result in no friction, on the contrary the friction is quite strong.
Note that I tried using both Unity Physics and Havok Physics with Unity 6000.1.13f1.

How should I disable friction for a specific entity completely? Did I make some mistake in my assumptions?

And here’s a video showcasing the issue as well:

The entity with 0 friciton is selected (you can notice the velocity increases on contact, but drops quickly due to friction).

Below is a screenshot of the settings I used:

Note, that the problem doesn’t persist when the surface the object interacts with has friciton disabled as well - however, I’d expect it to work just like it does with GameObjects where it’s possible to set per-entity.

In game objects, it’s not set per entity, it is a combination of the materials: https://docs.unity3d.com/6000.1/Documentation/Manual/collider-surfaces-combine.html
using: https://docs.unity3d.com/6000.1/Documentation/Manual/collider-surfaces-combine.html

This is also an option for ecs physics: https://docs.unity3d.com/Packages/com.unity.physics@1.3/api/Unity.Physics.Material.CombinePolicy.html

You need to set the enum, to the minimum value.

Thanks for the answer.

I already have it set to Minimum for the entity that should have friction disabled (as seen on the screenshot and video above).

Is the minimum set on the other material too? I haven’t used ecs physics, but in game object physics there’s a priority order when the two enums have different values.

Not as of now - but I wish to avoid modifying the friction for other entities, with the exception of few (like in the Player Controller), which is possible to do for the GameObjects.

If there is some priority as you suggest, do you know how to enforce it?

Otherwise the behaviour on the ECS side appears as a bug or at the very least discrepancy (as per-entity option for friction is basically ignored) compared to the ‘standard’ GameObject behaviour.

The priority in game objects physics material friction is dependent on the lower value. The one with the lower value takes precedence.

I’m not entirely sure how priority works in the ECS, but if you haven’t also set the other object’s material friction to minimum, then it’s likely not a bug. If it were, it would probably have been reported a long time ago. It would be quite obvious to anyone using materials, so this is likely the intended behavior.

In that case the priority isn’t in effect here, considering the friction of 0 is not being used, as that is the lowest value.

Either way, looking at the video, you can see that the friction is set to 0 and minimal - exactly how you’d implement this for GameObjects.

If it was required for all objects to have their friction set to 0 and minimal to account for few exceptions, then it effectively means that you have to disable friction globally, which to me doesn’t seem like the intended behaviour.

I don’t know if it is a (perhaps recent) bug, lacking feature (like many ECS features) or something else entirely. What is important is that I am looking for a solution - disabling friction for a single entity - as otherwise this is a roadblock that doesn’t allow me to achieve the desired behaviour in ECS.

You misunderstand how priority ordering works, this doesn’t mean that it is required for all objects to have their friction set to 0 and minimal to account for few exceptions, the value of the friction doesn’t matter at all. The value of the enum matters, and in the link for the ecs, the minimum value has the highest number.

You don’t need to disable friction for any entity, the value of the ordering which is the value that the enum has, has nothing to do with the value of the friction.

This is the way it works for game objects and I don’t see why it should be any different for ecs. You should read the manual and play with the examples to understand the physics better, this is the intended behavior for game objects.

Just to be sure, by ‘enum’ you mean the Friction Combine (or ‘CombinePolicy’)? - the one with 4 options:

  • Geometric Mean
  • Minimum
  • Maximum
  • Arithmetic Mean

If so, then it serves the purpose of combining the friction of the two colliding objects; in case of the Minimum, which is used here, it takes the lower of the two friction values.

If you’re saying that when two objects collide, the CombinePolicy used is determined by the highest of the two, then this doesn’t apply for GameObjects, which you can prove quite easily.
Below, I included a sample project comparing the behaviour between ECS and GO:
friction_disable.unitypackage (142.5 KB)

  • To install it, make sure you have the packages:

    • Entities
    • Entities Graphics
    • Unity Physics
    • And then simply import it through Assets>Import Package>Custom Package…
    • And open the “MainScene” in the ‘Scenes’ folder
  • It has two parent objects: ‘GO’ and ‘ECS

  • The ‘ECS’ includes a subscene with a single yellow box and a blue plane. The box uses a ‘Frictionless’ Physics material, which sets its friction to 0, while also choosing ‘Minimal’ CombinePolicy. The plane uses a ‘FrictionMaterial’, which has friction of 0.6 and uses ‘Average’ CombinePolicy.

  • The ‘GO’ has the exact same setup, except the objects are not inside a subscene and the plane is red.

  • Then there are two scripts, again one for ECS and one for GO. The GO script is attached to the particular yellow box directly, and it simply applies an impulse of 5 in the Start method.

  • Then there is a similar System for the ECS side, which queries for PhysicsVelocity component and similarly applies force to it and then disables itself.

You can run the experiment by just hitting play, however make sure that the subscene is closed.
While the setup on the ECS and GO side is practically identical, the behaviour is not. GO object slides indefinitely, but the ECS is stopped by friction very quickly.

The only way to make the ECS object (that I have found) ignore friction as well, is to apply the same ‘Frictionless’ material to the plane it is interacting with; this would however mean that all objects need to have this ‘Minimal’ CombinePolicy, even if I other options (like the Geometric Mean) are preferable.

As you can see, the behaviour is not identical. While on the GO side, the friction is completely disabled for the object, it isn’t for ECS, which I don’t consider to be typical.

Here is a video showcasing the situation and the setup, so that it’s not necessary to download the example scene.

The video’s description has more details.

No, that’s not what I’m saying. I’m not saying anything different from what’s stated in the manual pages I linked. In any case, I don’t think this conversation is going anywhere. If you’re certain it’s a bug, then go ahead and report it.

Thank you for your effort, I have already reported the issue as a bug and I am hopeful it will be noticed here as well, I tried to document it as well as I could.

You may refer to the documentation of Custom Physics Materials here: Custom Physics Materials | Unity Physics | 1.4.0-pre.4

As you can see in the initial screenshot I sent, all it set up according to the manual. The latest video I posted should serve as sufficient reference as to what the setup is as well.

Unity Physics (ECS) and GameObject-based physics (PhysX) are two completely separate physics engines. The original question is about ECS. These two systems work independently and follow different programming paradigms. Assumptions about one should not be made based on how the other works.

I don’t understand why you think I’m making assumptions about how they work, quite the opposite. I’m explaining that there shouldn’t be any difference in physics laws between the two systems, because this has nothing to do with the programming paradigm.

Since I don’t know the background of every developer, and some may come from non-physics-heavy fields like art, let me explain in simple terms:

In physics, there are some fundamental laws known as Newton’s laws of motion. The third law, the law of action and reaction, states that when two bodies interact, they exert forces on each other that are equal in magnitude and opposite in direction.

These laws must be followed by all physics engines, regardless of the programming paradigm or system in use. Friction is considered a force in physics, so when two objects experience friction, the forces must be equal in magnitude and opposite in direction. The only way to ensure this, when the two bodies have different materials with potentially different friction calculations, is to impose a specific ordering in how friction is resolved, so that the same rule applies to both bodies.

In Unity, this ordering is determined by comparing the values of the enum that defines the friction combine policy. If you had opened the package provided by the OP, you would see that this is indeed the case: there is an ordering mechanism for both physics systems. Without such ordering, the system would not be able to comply with Newton’s third law.

The difference in behavior arises from how this ordering is defined, it is implemented differently in the two enums. In PhysX, the enum is defined as follows:

public enum PhysicsMaterialCombine
    {
        Average = 0,
        Multiply,
        Minimum,
        Maximum
    }

and the ecs physics like this:

public enum CombinePolicy : byte
        {
            /// <summary>   sqrt(a * b) </summary>
            GeometricMean,
            /// <summary>   min(a, b) </summary>
            Minimum,
            /// <summary>   max(a, b) </summary>
            Maximum,
            /// <summary>   (a + b) / 2. </summary>
            ArithmeticMean
        }

I’m not sure why this happened, but there is no bug here, and no assumptions were made. There’s no reason the ECS system shouldn’t have an ordering mechanism, just like PhysX does, because this has nothing to do with the underlying systems or programming paradigm. It’s simply how physics works.

The difference lies in how the ordering is calculated, based on how the enums are defined. This results in different behaviors. In PhysX, the Minimum value takes precedence over Average, so the object keeps moving indefinitely. In ECS, Average takes precedence over Minimum, so the object comes to a stop after a while.

Again, whether it’s ECS or not doesn’t matter, physics laws remain the same. The approach used for GameObjects, where some form of ordering is applied to calculate friction, should also apply in ECS or any other physics system that handles friction differently across materials. Why Unity chose to implement a different ordering I don’t know, but no assumptions were made based on the system. This is just how physics works.

That is precisely the source of the discrepancy, thank you.

It is unusual why the the order is different - perhaps because in the PhysicsShapeAuthoring sample scripts, the new default is GeometricMean, however GameObjects baked with a Collider component by default uses ArithmeticMean, so there’s a mismatch between the defaults. But that is only a guess.

I wonder if there is a way to manually enforce the priority or in some other way disable (override) friction of an individual entity ECS. Setting all other colliders to GeometricMean manually will have to do for now, but alternative solutions would be welcome.

I don’t believe there’s a way to change the order unless Unity modifies the enum itself, as the ordering is determined by the enum values. The issue with that, is that it would break all existing projects that currently use friction in ECS Physics.

I choose to believe that Unity has a specific reason for using a different calculation order. Otherwise, it would mean they’ve broken compatibility with PhysX’s ordering without being able to fix it, since doing so would now break compatibility with existing projects, for no good reason.

Agree with meredoth here. If collision material combine flags have different priority in PhysX than they have in ECS physics, it would be a good idea to modify ECS physics so that both match.

Not all physics engines are guaranteed to behave the same, even if they follow the same physical laws since implementation details differ (different numerical integration methods, different constraint solvers, etc) and this has an impact on results. But this is low-hanging fruit, and Unity should strive to keep differences between physics engines to a minimum - specially now that Unity’s plan is to allow users to switch to a different engine/backend easily. Hope we don’t end up in the whole SRP situation again.

Agreed. Feel free to file this as a bug and report back with the issue ID.

We are constantly working towards reducing differences as much as possible if the behavior is the correct one, or an already established one that is equivalently correct, as is the case here.