Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to apply physics to a selected game object in the editor?

Discussion in 'Scripting' started by Magnilum, Dec 2, 2023.

  1. Magnilum

    Magnilum

    Joined:
    Jul 1, 2019
    Posts:
    241
    Hello everyone,

    I am trying to make a tool in Unity to easily manage prefabs. I have seen that is possible to simulate physics in the editor by calling Physics.Simulate, I also discovered that another method exists which is PhysicsScene.Simulate.

    Even if I don't really understand the difference between them, both are simulating physics in the entire scene.

    That is why I am looking for a way to apply physic on one game object or several but the ones I have choosen.

    I have seen that is possible and even without rigidbody component attach to it but I don't manage to find where I saw this.

    I hope you could help me.
     
  2. tsukimi

    tsukimi

    Joined:
    Dec 10, 2014
    Posts:
    76
    At default, all rigidbodies belongs to an default PhysicsScene (different from normal scene), and Physics.Simulate simulates the default PhysicsScene. In other hand, you can choose create your own seperate PhysicsScene while you load/create a scene, using localPhysicsMode.Physics3D, so objects in that scene won't be infected by the default Physics Updates. In such situation, you have to use scene.GeyPhysicsScene(), and use PhysicsScene.Simulate to simulate the local phyics for objects only in that scene. (Unity's Phsyics system won't auto simulate local ShysicsScene for you.)
     
  3. Magnilum

    Magnilum

    Joined:
    Jul 1, 2019
    Posts:
    241
    Thank for your answer!

    I am not sure to get everything. So I need to create a temporary scene and add the game object I want to simulate to this scene. Then simulate the scene and voila?!
     
  4. Magnilum

    Magnilum

    Joined:
    Jul 1, 2019
    Posts:
    241
    I have experimented with this a bit but it seems to work only in play mode.

    What I would like it to simulate a certain game object in the Editor.