Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Closestep | The time to advance physics by. |
void Whether the simulation was run or not. Running the simulation during physics callbacks will always fail.
Simulate physics associated with this PhysicsScene.
Calling this method causes the physics to be simulated over the specified step
time. Only the physics associated with this PhysicsScene will be simulated. If this PhysicsScene is not the default physics Scene (see Physics.defaultPhysicsScene) then it is associated with a specific Scene and as such, only components added to that Scene are affected when running the simulation.
If you pass framerate-dependent step values (such as Time.deltaTime) to the physics engine, your simulation will be less deterministic because of the unpredictable fluctuations in framerate that can arise. To achieve more deterministic physics results, you should pass a fixed step value to PhysicsScene.Simulate every time you call it.
You can call PhysicsScene.Simulate in the Editor outside of play mode however caution is advised as this will cause the simulation to move GameObject that have a Rigidbody component attached. When simulating in the Editor outside of play mode, a full simulation occurs for all physics components including Rigidbody, Collider and Joint including the generation of contacts however contacts are not reported via the standard script callbacks. This is a safety measure to prevent allowing callbacks to delete objects in the Scene which would not be an undoable operation.
Here is an example of a basic simulation that implements what's being done in the automatic simulation mode.
using UnityEngine; using UnityEngine.SceneManagement;
public class MultiScenePhysics : MonoBehaviour { private Scene extraScene;
public void Start() { // First create an extra scene with local physics extraScene = SceneManager.CreateScene("Scene", new CreateSceneParameters(LocalPhysicsMode.Physics3D));
// Mark the scene active, so that all the new GameObjects end up in the newly created scene SceneManager.SetActiveScene(extraScene);
PopulateExtraSceneWithObjects(); }
public void FixedUpdate() { // All of the non-default physics scenes need to be simulated manually var physicsScene = extraScene.GetPhysicsScene(); physicsScene.Simulate(Time.fixedDeltaTime); }
public void PopulateExtraSceneWithObjects() { // Create GameObjects for physics simulation var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.AddComponent<Rigidbody>(); sphere.transform.position = Vector3.up * 4; } }
Additional resources: Physics.Simulate.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.