Physics Components
Both engines use a similar physics model: a physics body for dynamics and collision shapes for detection. The names and setup differ:
Physics Components
| Unreal Engine | Unity | Note |
|---|---|---|
UStaticMeshComponent (Simulate Physics) | Rigidbody | Enables physics simulation |
UBoxComponent | BoxCollider | Box-shaped collision |
USphereComponent | SphereCollider | Sphere-shaped collision |
UCapsuleComponent | CapsuleCollider | Capsule-shaped collision |
UPhysicsMaterial | PhysicMaterial | Friction, bounciness settings |
Collision Channels | Layers + Layer Collision Matrix | What collides with what |
Rigidbody and Collider are separate components. In Unreal, physics simulation is a property on mesh components. Unity's separation is more modular.Collision Detection
Unreal uses Collision Channels and Object Types. Unity uses a Layer system with a Layer Collision Matrix (set in Project Settings → Physics).
Collision Layers
| Unreal Engine | Unity | Note |
|---|---|---|
WorldStatic | Default | Static environment |
WorldDynamic | Default (with Rigidbody) | Moving objects |
Pawn | Player (custom layer) | Player characters |
Projectile (custom) | Projectile (custom layer) | Bullets, arrows, etc. |
Trigger (Overlap) | Trigger (Is Trigger checkbox) | Non-blocking detection zones |
Collision Callbacks
Unreal uses Hit and Overlap events. Unity splits them into Collision (physical contact) and Trigger (non-physical overlap):
// Unreal: Overlap events
UFUNCTION()
void OnOverlapBegin(
UPrimitiveComponent* OverlappedComp,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult);
// Binding in constructor
CollisionComp->OnComponentBeginOverlap
.AddDynamic(this, &AMyActor::OnOverlapBegin);// Unity: Trigger callbacks (Is Trigger = true)
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
Debug.Log("Player entered trigger!");
}
void OnTriggerExit(Collider other)
{
Debug.Log("Something left the trigger");
}
// Collision callbacks (Is Trigger = false)
void OnCollisionEnter(Collision collision)
{
Debug.Log("Hit: " + collision.gameObject.name);
// collision.contacts gives contact points
}Raycasting
Both engines have raycasting for line-of-sight checks, ground detection, and shooting. The API is quite similar:
// Unreal: Line trace
FHitResult Hit;
FVector Start = GetActorLocation();
FVector End = Start + GetActorForwardVector() * 1000.f;
FCollisionQueryParams Params;
Params.AddIgnoredActor(this);
bool bHit = GetWorld()->LineTraceSingleByChannel(
Hit, Start, End,
ECC_Visibility, Params);
if (bHit)
{
AActor* HitActor = Hit.GetActor();
FVector HitPoint = Hit.ImpactPoint;
}// Unity: Raycast
Ray ray = new Ray(transform.position,
transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 1000f))
{
GameObject hitObject = hit.collider.gameObject;
Vector3 hitPoint = hit.point;
Debug.Log("Hit: " + hitObject.name);
}
// With layer mask (only hit "Enemy" layer)
int enemyLayer = LayerMask.GetMask("Enemy");
if (Physics.Raycast(ray, out hit, 1000f, enemyLayer))
{
// Only hits objects on Enemy layer
}Physics Best Practices
FixedUpdate(), not Update(). This matches Unreal's substepping philosophy.Deep Dive: 2D vs 3D Physics
Unity has separate 2D and 3D physics engines. If you're making a 2D game, use Rigidbody2D, BoxCollider2D, Physics2D.Raycast, etc. They don't interact with 3D physics.
3D vs 2D Physics
| Unreal Engine | Unity |
|---|---|
Rigidbody (3D) | Rigidbody / Rigidbody2D |
BoxCollider (3D) | BoxCollider / BoxCollider2D |
Physics.Raycast | Physics.Raycast / Physics2D.Raycast |
OnTriggerEnter | OnTriggerEnter / OnTriggerEnter2D |