How to access async physics in UE5

I’m looking to create my own physics based movement for an actor using async physics in UE5. While there is documentation on what async physics achieves (improved determinism etc), there isn’t really any on how to implement it. I have had a look at the Chaos Vehicle Plugin where it is used, but it’s pretty hard to understand exactly what’s going on. I was hoping there would be a simple C++ callback where I could put my physics code! Does anyone perhaps have a decent understanding and could give a breakdown to help me/the community out?

3 Likes

Today, I’m also currently creating a physics-based locomotion process and running into this problem.

Fortunately, UE5.1 exposed the functions you see in the image.


As the name suggests, this function is executed during physics calculations.

I think this is a big advantage for games that rely on physics.

I’m glad if you can use it as a reference.

I don’t know why Epic didn’t publish such a basic function in the first place

2 Likes

Oh wow, that would have made my life a lot easier! :smiling_face_with_tear: It was such a pain trying to implement it for multiplayer that I moved on to another project. Anyway, thanks for the update, I appreciate it!

Hello !

I also just noticed this new Event. I really need to get or set Velocity, Location, or add Forces every Async Ticks. But I can’t find any Function to do that. The basic Get Location or Get Component Velocity get me (every Async Physics Tick) the values of the Event Tick… Impossible to handle physics with that.

I only see the function Get Body Instance Async Physics Tick Handle that seems to get the Async version of a component. But the only thing I can do with it is add a force with Add Force but any Get or Set Location, Velocity

Please, anyone have a solution ?

1 Like

Hi,

i’m using 5.1 but when try to override the AsyncPhysicsTickComponent() function it says that did not override any base class method.

Is this still working. What should the (inherited) base class be ?

Thanks !

To change the position or velocity inside the physics thread, you need to control it on the c++ side.

You can do it with functions like images.

UE5_PhysThread

The meaning of the function is as follows

・AddForce(): Add force.
・AddTorque(): Add torque

・V(): Acquire the velocity.
・SetV(): Sets the speed.

・X(): Get the position
・SetX(): Sets the position.

・R(): Gets the rotation.
・SetR(): Sets the rotation.

1 Like

Thanks ! But I’m using Blueprint… :smiling_face_with_tear:

Did you make a blueprint function yourself in the meantime for getting async velocity or location? I don’t see anything in 5.2 default blueprint library that would help here. Seems like we are still supposed to do async physics in C++? :upside_down_face:

No, I haven’t created one yet.

on the game thread instead, i.e.
After determining the position, velocity, and rotation in BP, we implemented the ability to adapt it to the values of the physical thread.

Looks like we’re still supposed to do asynchronous physics in C++?
Yes, probably.
Because it is moved by physical calculation, it is necessary to perform repeated processing at fixed time intervals, which is not compatible with BP that is assumed to be event-driven. I think it’s best to do it in C++, including in terms of performance.

Furthermore, there is a bug in the AddForce function that can be accessed from Get Body Instance Async Physics Tick Handle published on BP.
When I call it, it freezes for a few seconds.

I think the reason is that access from the game thread is not safe.

In any case, from the BP and also from the C++ side
Get type
・GetComponent Velocity
・GetActorLocation
Set type
・SetPhysicsLinearVelocity
・SetActorLocation
etc. are values on the game thread, so to access the values on the physical thread you need to access them from the C++ side.

1 Like

However, that would be very difficult (especially for people who don’t know C++).
I am thinking of creating a function to obtain and set the values ``position, rotation, velocity, angular velocity, force, torque’’ on the physical thread from BP.

This is what I felt when creating physics-based character movements.
I’m a little dissatisfied with UE’s lack of better information for some reason when creating movements.

1 Like

Thanks for coming back to this! :slight_smile:

For my application it proved sufficient to just average the velocity values every async tick. So whenever the new value from event tick comes in, it doesn’t jump immediately to it.

I’m dissatisfied with UE’s lack of information in general :laughing:
It’s only rarely that you get good information on the detailed workings of blueprint functions. Sure, you can look into the source code, but usually googling is faster, if it’s a common issue at least.
Maybe they will do some bigger changes here with the new movement system that they are working on.

1 Like

Why it’s c++ only. Any idea on that?.

Why it’s c++ only.
I do not understand

Currently I have created a function that can apply values in an asynchronous physical thread from BP.

As shown in the image below

This is a function that records the value on BP and adds it to the position of the rigid body on the physics thread on the C++ side.

1 Like

However, C++ is required for image-like approaches.

How to access asynchronous physics with BP only
By using “Event Async Physics Tick”.

Even if you use that function, you can only use the “AddForce” function on BP.

In other words, you cannot set position, rotation, or speed on BP, nor can you apply torque.

So the solution is
1: Wait until Epic implements it
2: Ask anyone who runs C++.
This is the only way I can think of.

I also extended “AddRigidPos” in the image above
I’m trying to create a function that applies values to asynchronous physics from BP.

I understand that this is important for people like me who create physically based character controllers without using “CharacterMovementComponent”.

What include do we need to add, when we would like to use this AddForce() function?

It works by passing a three-dimensional vector value, that is, “FVector” type, as the argument.