Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


PhysicsWorldDefinition

A PhysicsWorld definition used to specify important initial properties.
Read time 7 minutesLast updated 3 days ago

Definition

public struct PhysicsWorldDefinition : IEquatable<PhysicsWorldDefinition>

Remarks

For more information about definitions, refer to PhysicsBodyDefinition.
Additional Resources: PhysicsBodyDefinition

Examples

// Create a world definition, configure it, then create a world from it.using UnityEngine;using Unity.U2D.Physics;public class WorldDefinitionExample : MonoBehaviour{ void Start() { PhysicsWorldDefinition worldDefinition = new PhysicsWorldDefinition(); worldDefinition.gravity = new Vector2(0f, -9.81f); PhysicsWorld world = PhysicsWorld.Create(worldDefinition); }}

Constructors

Constructor

Description

PhysicsWorldDefinition()Create a default PhysicsWorld definition.
PhysicsWorldDefinition(System.Boolean)Create a default PhysicsWorld definition.

Properties

Property

Description

autoBodyUpdateCallbacksControls if body update callback targets are automatically called. See PhysicsWorld.SendBodyUpdateCallbacks.
autoJointThresholdCallbacksControls if joint threshold callback targets are automatically called. See PhysicsWorld.SendJointThresholdCallbacks.
bounceThresholdAdjust the bounce threshold, usually in meters per second. It is recommended not to make this value very small because it will prevent bodies from sleeping. See _bounceThreshold.
capacityThe expected world capacities used to presize internal allocations when the PhysicsWorld is created. All counts default to zero, in which case the engine uses its own minimum defaults. Presizing avoids reallocations during the first simulation steps for worlds with a known object count. Every count is in the range zero to PhysicsWorld.WorldCapacity.MaxCapacity and any value outside that range is clamped into it.
contactDampingThe contact bounciness with 1 being critical damping (non-dimensional). See _contactDamping.
contactFilterCallbacksControls if contact filter callbacks will be called. A contact filter callback allows direct control over whether a contact will be created between a pair of shapes. This applies to both triggers and non-triggers but only with Dynamic bodies. These are relatively expensive so disabling them can provide a significant performance benefit. A contact filter callback will call the _callbackTarget for both shapes involved if they implement PhysicsCallbacks.IContactFilterCallback.
contactFrequencyThe contact stiffness, in cycles per second. See _contactFrequency.
contactHitEventThresholdThe contact hit event threshold controls the collision speed needed to generate a contact hit event, usually in meters per second. See PhysicsEvents.ContactHitEvent. See _contactHitEventThreshold.
contactRecycleDistanceThe contact recycle distance, in meters. Setting this to zero disables contact point recycling. Contact recycling reuses contact points across simulation time-steps when the relative movement is small. This feature improves stability and performance by around 25% (approximately). Contact points are not recalculated until shapes move more than 5cm (default) relative to each other. Contact recycling skips some updates such as friction, pre-solve (etc) until the contacts are no longer recycled. See _contactRecycleDistance.
contactSpeedThe contact speed used to solve overlaps, in meters per second. See _contactSpeed.
continuousAllowedControls if continuous collision detection will be used between Dynamic and Static bodies. Generally you should keep continuous collision enabled to prevent fast moving objects from going through Static objects. The performance gain from disabling continuous collision is minor. See _continuousAllowed
drawAtTransformDraws a body, its shapes and its joints at its assigned Transform's current world pose instead of its simulated physics pose, whenever that body is writing its pose to the Transform. Turning this on costs extra computation for every body drawn, and what gets drawn is no longer a picture of the simulation: shapes can appear to be touching, overlapping, or separated from each other when the simulation itself says otherwise.
drawColorsControls what colors are used to draw PhysicsBody, PhysicsShape, PhysicsJoint etc. See PhysicsWorld.DrawColors.
drawContactTypeControls how contact points are drawn. See PhysicsWorld.DrawContactType.
drawFillAlphaControls the draw fill alpha. This is used to scale the interior fill alpha and is only used when PhysicsWorld.DrawFillOptions.Outline is used so that the interior color can be distinguished from the outline color by transparency. See _drawFillAlpha.
drawFillOptionsControls how shape geometry is filled when drawing. See PhysicsWorld.DrawFillOptions.
drawFilterLimits what gets drawn to a narrow selection. This only affects PhysicsWorld.DrawOptions that are drawing all bodies, shapes etc. It does not affect selected elements or custom drawing. See PhysicsWorld.IgnoreFilter.
drawForceScaleControls the joint contact force scale used when drawing contact forces. See _drawForceScale.
drawNormalScaleControls the joint contact normal scale used when drawing contact normals. See _drawNormalScale.
drawOptionsLimits what gets drawn to a broad selection. See PhysicsWorld.DrawOptions.
drawOrderControls the relative order this world is drawn in across all worlds. Worlds with a lower draw order are drawn first, so worlds with a higher draw order are drawn on top. See _drawOrder.
drawPointScaleControls the draw point scale used when drawing points. See _drawPointScale.
drawTargetControls which Unity editor views the world is drawn into (Scene view, Game view or both). This only filters the built-in viewport rendering; it does not control whether drawing occurs at all. See _drawTarget.
drawThicknessControls the draw thickness (outline and orientation). See _drawThickness.
eventGroupingAllowedControls if contact and trigger begin/end events for shapes assigned a group are marked as being the first or last event between the two groups involved. This allows the many events produced between two groups of shapes to be reduced to a single begin and end, such as when treating multiple shapes on one body as a single object. The marking is only calculated for shapes assigned a group and only when a begin or end event is produced, so the cost of leaving this enabled is minor.
gravityGet/Set the gravity vector applied to all bodies in the world, usually in m/s^2. See _gravity.
maximumLinearSpeedGet/Set the maximum linear speed. See _maximumLinearSpeed.
preContactCallbacksControls if pre-contact and pre-continuous callbacks will be called. This only applies to Dynamic bodies and is ignored for triggers. These are relatively expensive so disabling them can provide a significant performance benefit.
simulationSubStepsGet/Set the simulation sub-steps to use during simulation. See PhysicsWorld.Simulate. See _simulationSubSteps.
simulationTypeGet/Set the simulation mode which controls when or if the simulation will be automatically simulated. See PhysicsWorld.SimulationType and PhysicsWorld.Simulate.
simulationWorkersGet/Set the simulation worker count for the world. A single simulation worker is always used for simulation therefore a worker count of one means single thread simulation only. The actual quantity of workers used will always be capped to those available on the current device and reading the property will return the number of workers actually being used by the device. Changing the worker count continuously is not recommend and will impact performance as it requires the task queue be recreated. See _simulationWorkers.
sleepingAllowedControls if bodies go to sleep when not moving and not interacting. Sleeping can provide a significant performance improvement when many Dynamic or Kinematic bodies are in the world. See _sleepingAllowed
syncInterpolationControls if an extra write pass prior to the script fixed-update callback is made for any interpolation tweens to ensure that transforms are synchronized to the final body pose. Because this is an extra write pass, it has an impact on overall performance so only enable if you require transforms synchronized this way.
transformPlaneControls the transform plane that the world uses when writing transforms. See _transformWriteMode. See _transformPlane.
transformPlaneCustomControls the transformation for the PhysicsWorld.TransformPlane.Custom to allow transformation writing and reading to/from a custom space. See PhysicsWorld.TransformPlaneCustom.
transformTweenModeControls if and how Transform tweens are calculated and/or written. Transform tweening is where bodies that have their _transformObject set, write to the Transform each frame depending on the specific body PhysicsBody.TransformWriteMode set. Regardless of this setting, Transform tweening is never used if the _simulationType is PhysicsWorld.SimulationType.Update or _transformWriteMode is PhysicsWorld.TransformWriteMode.Off.
transformWriteModeControls how transform writing is handled. Only bodies that have their _transformWriteMode active and produce a PhysicsEvents.BodyUpdateEvent will write to a transform. See PhysicsWorld.TransformWriteMode.

Static Properties

Property

Description

defaultDefinitionGet a default PhysicsWorld definition.