Reputation: 351
I am wondering is there any way to let gravity affect items in editor mode? Normally I set the rigidbody to a object and hit play button, then I can see the object will be falling according to gravity. But How can I do this without hitting play button?
I googled a lot and I can't find any document showing me how to do it.
Thanks
Upvotes: 1
Views: 3091
Reputation: 23
I use this asset called 'Editor Physics Simulator' from the Unity asset store.
Link to asset: https://assetstore.unity.com/packages/tools/level-design/editor-physics-simulator-221538
Upvotes: 0
Reputation: 20259
This answer by ThePilgrim on the Unity Q&A site seems to answer this question:
You can simulate physics in the editor by setting Physics.autoSimulation to false, and using Physics.Simulate() to advance physics frame by frame until your objects are settled.
Here is an example editor window:
using UnityEditor; using UnityEngine; public class ScenePhysicsTool : EditorWindow { private void OnGUI() { if (GUILayout.Button("Run Physics")) { StepPhysics(); } } private void StepPhysics() { Physics.autoSimulation = false; Physics.Simulate(Time.fixedDeltaTime); Physics.autoSimulation = true; } [MenuItem("Tools/Scene Physics")] private static void OpenWindow() { GetWindow<ScenePhysicsTool>(false, "Physics", true); } }
Upvotes: 3