Przeglądaj źródła

Physics component no longer return shared pointers to their internals, as they should never be owned by external code

BearishSun 9 lat temu
rodzic
commit
5209726e0d

+ 1 - 1
BansheeCore/Include/BsCBoxCollider.h

@@ -37,7 +37,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the box collider that this component wraps. */
 	    /**	Returns the box collider that this component wraps. */
-		SPtr<BoxCollider> _getInternal() const { return std::static_pointer_cast<BoxCollider>(mInternal); }
+		BoxCollider* _getInternal() const { return static_cast<BoxCollider*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 1 - 1
BansheeCore/Include/BsCCapsuleCollider.h

@@ -49,7 +49,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the capsule collider that this component wraps. */
 	    /**	Returns the capsule collider that this component wraps. */
-		SPtr<CapsuleCollider> _getInternal() const { return std::static_pointer_cast<CapsuleCollider>(mInternal); }
+		CapsuleCollider* _getInternal() const { return static_cast<CapsuleCollider*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 4 - 1
BansheeCore/Include/BsCCharacterController.h

@@ -100,7 +100,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the character controller that this component wraps. */
 	    /**	Returns the character controller that this component wraps. */
-		SPtr<CharacterController> _getInternal() const { return std::static_pointer_cast<CharacterController>(mInternal); }
+		CharacterController* _getInternal() const { return static_cast<CharacterController*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 
@@ -132,6 +132,9 @@ namespace BansheeEngine
 		/** Updates the dimensions of the controller by taking account scale of the parent scene object. */
 		/** Updates the dimensions of the controller by taking account scale of the parent scene object. */
 		void updateDimensions();
 		void updateDimensions();
 
 
+		/** Destroys the internal character controller representation. */
+		void destroyInternal();
+
 		/** Triggered when the internal controller hits a collider. */
 		/** Triggered when the internal controller hits a collider. */
 		void triggerOnColliderHit(const ControllerColliderCollision& value);
 		void triggerOnColliderHit(const ControllerColliderCollision& value);
 
 

+ 4 - 1
BansheeCore/Include/BsCCollider.h

@@ -74,7 +74,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 		/** Returns the Collider implementation wrapped by this component. */
 		/** Returns the Collider implementation wrapped by this component. */
-		SPtr<Collider> _getInternal() const { return mInternal; }
+		Collider* _getInternal() const { return mInternal.get(); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 
@@ -107,6 +107,9 @@ namespace BansheeEngine
 		/** Creates the internal representation of the Collider and restores the values saved by the Component. */
 		/** Creates the internal representation of the Collider and restores the values saved by the Component. */
 		virtual void restoreInternal();
 		virtual void restoreInternal();
 
 
+		/** Destroys the internal collider representation. */
+		void destroyInternal();
+
 		/** 
 		/** 
 		 * Checks is the provided rigidbody a valid parent for this collider. 
 		 * Checks is the provided rigidbody a valid parent for this collider. 
 		 *
 		 *

+ 1 - 1
BansheeCore/Include/BsCD6Joint.h

@@ -82,7 +82,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the D6 joint that this component wraps. */
 	    /**	Returns the D6 joint that this component wraps. */
-		SPtr<D6Joint> _getInternal() const { return std::static_pointer_cast<D6Joint>(mInternal); }
+		D6Joint* _getInternal() const { return static_cast<D6Joint*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 1 - 1
BansheeCore/Include/BsCDistanceJoint.h

@@ -58,7 +58,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the distance joint that this component wraps. */
 	    /**	Returns the distance joint that this component wraps. */
-		SPtr<DistanceJoint> _getInternal() const { return std::static_pointer_cast<DistanceJoint>(mInternal); }
+		DistanceJoint* _getInternal() const { return static_cast<DistanceJoint*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 1 - 1
BansheeCore/Include/BsCFixedJoint.h

@@ -25,7 +25,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the fixed joint that this component wraps. */
 	    /**	Returns the fixed joint that this component wraps. */
-		SPtr<FixedJoint> _getInternal() const { return std::static_pointer_cast<FixedJoint>(mInternal); }
+		FixedJoint* _getInternal() const { return static_cast<FixedJoint*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 1 - 1
BansheeCore/Include/BsCHingeJoint.h

@@ -49,7 +49,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the hinge joint that this component wraps. */
 	    /**	Returns the hinge joint that this component wraps. */
-		SPtr<HingeJoint> _getInternal() const { return std::static_pointer_cast<HingeJoint>(mInternal); }
+		HingeJoint* _getInternal() const { return static_cast<HingeJoint*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 4 - 1
BansheeCore/Include/BsCJoint.h

@@ -62,7 +62,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 		/** Returns the Joint implementation wrapped by this component. */
 		/** Returns the Joint implementation wrapped by this component. */
-		SPtr<Joint> _getInternal() const { return mInternal; }
+		Joint* _getInternal() const { return mInternal.get(); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 
@@ -96,6 +96,9 @@ namespace BansheeEngine
 		/** Creates the internal representation of the Joint and restores the values saved by the Component. */
 		/** Creates the internal representation of the Joint and restores the values saved by the Component. */
 		virtual void restoreInternal();
 		virtual void restoreInternal();
 
 
+		/** Destroys the internal joint representation. */
+		void destroyInternal();
+
 		/** Notifies the joint that one of the attached rigidbodies moved and that its transform needs updating. */
 		/** Notifies the joint that one of the attached rigidbodies moved and that its transform needs updating. */
 		void notifyRigidbodyMoved(const HRigidbody& body);
 		void notifyRigidbodyMoved(const HRigidbody& body);
 
 

+ 1 - 1
BansheeCore/Include/BsCMeshCollider.h

@@ -31,7 +31,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the mesh collider that this component wraps. */
 	    /**	Returns the mesh collider that this component wraps. */
-		SPtr<MeshCollider> _getInternal() const { return std::static_pointer_cast<MeshCollider>(mInternal); }
+		MeshCollider* _getInternal() const { return static_cast<MeshCollider*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 1 - 1
BansheeCore/Include/BsCPlaneCollider.h

@@ -37,7 +37,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the plane collider that this component wraps. */
 	    /**	Returns the plane collider that this component wraps. */
-		SPtr<PlaneCollider> _getInternal() const { return std::static_pointer_cast<PlaneCollider>(mInternal); }
+		PlaneCollider* _getInternal() const { return static_cast<PlaneCollider*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 7 - 1
BansheeCore/Include/BsCRigidbody.h

@@ -151,7 +151,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 		/** Returns the Rigidbody implementation wrapped by this component. */
 		/** Returns the Rigidbody implementation wrapped by this component. */
-		SPtr<Rigidbody> _getInternal() const { return mInternal; }
+		Rigidbody* _getInternal() const { return mInternal.get(); }
 
 
 		/** Sets that joint that this rigidbody is attached to. Allows the rigidbody to notify the joint when it moves. */
 		/** Sets that joint that this rigidbody is attached to. Allows the rigidbody to notify the joint when it moves. */
 		void _setJoint(const HJoint& joint) { mParentJoint = joint; }
 		void _setJoint(const HJoint& joint) { mParentJoint = joint; }
@@ -181,6 +181,12 @@ namespace BansheeEngine
 		/** Checks if the rigidbody is nested under another rigidbody, and throws out a warning if so. */
 		/** Checks if the rigidbody is nested under another rigidbody, and throws out a warning if so. */
 		void checkForNestedRigibody();
 		void checkForNestedRigibody();
 
 
+		/** Appends Component referenes for the colliders to the collision data. */
+		void processCollisionData(CollisionData& data);
+
+		/** Destroys the internal rigidbody representation. */
+		void destroyInternal();
+
 		/** Triggered when the internal rigidbody begins touching another object. */
 		/** Triggered when the internal rigidbody begins touching another object. */
 		void triggerOnCollisionBegin(const CollisionData& data);
 		void triggerOnCollisionBegin(const CollisionData& data);
 
 

+ 1 - 1
BansheeCore/Include/BsCSliderJoint.h

@@ -43,7 +43,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the slider joint that this component wraps. */
 	    /**	Returns the slider joint that this component wraps. */
-		SPtr<SliderJoint> _getInternal() const { return std::static_pointer_cast<SliderJoint>(mInternal); }
+		SliderJoint* _getInternal() const { return static_cast<SliderJoint*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 1 - 1
BansheeCore/Include/BsCSphereCollider.h

@@ -37,7 +37,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the sphere collider that this component wraps. */
 	    /**	Returns the sphere collider that this component wraps. */
-		SPtr<SphereCollider> _getInternal() const { return std::static_pointer_cast<SphereCollider>(mInternal); }
+		SphereCollider* _getInternal() const { return static_cast<SphereCollider*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 1 - 1
BansheeCore/Include/BsCSphericalJoint.h

@@ -37,7 +37,7 @@ namespace BansheeEngine
 		/** @cond INTERNAL */
 		/** @cond INTERNAL */
 
 
 	    /**	Returns the spherical joint that this component wraps. */
 	    /**	Returns the spherical joint that this component wraps. */
-		SPtr<SphericalJoint> _getInternal() const { return std::static_pointer_cast<SphericalJoint>(mInternal); }
+		SphericalJoint* _getInternal() const { return static_cast<SphericalJoint*>(mInternal.get()); }
 
 
 		/** @endcond */
 		/** @endcond */
 
 

+ 3 - 3
BansheeCore/Include/BsCollider.h

@@ -24,8 +24,8 @@ namespace BansheeEngine
 		inline void setIsTrigger(bool value);
 		inline void setIsTrigger(bool value);
 		inline bool getIsTrigger() const;
 		inline bool getIsTrigger() const;
 
 
-		inline void setRigidbody(const SPtr<Rigidbody>& value);
-		SPtr<Rigidbody> getRigidbody() const { return mRigidbody; }
+		inline void setRigidbody(Rigidbody* value);
+		Rigidbody* getRigidbody() const { return mRigidbody; }
 
 
 		inline void setMass(float mass);
 		inline void setMass(float mass);
 		inline float getMass() const;
 		inline float getMass() const;
@@ -66,7 +66,7 @@ namespace BansheeEngine
 	protected:
 	protected:
 		FCollider* mInternal = nullptr;
 		FCollider* mInternal = nullptr;
 		PhysicsObjectOwner mOwner;
 		PhysicsObjectOwner mOwner;
-		SPtr<Rigidbody> mRigidbody;
+		Rigidbody* mRigidbody = nullptr;
 		Vector3 mScale = Vector3::ONE;
 		Vector3 mScale = Vector3::ONE;
 	};
 	};
 }
 }

+ 5 - 5
BansheeCore/Include/BsPhysicsCommon.h

@@ -20,15 +20,15 @@ namespace BansheeEngine
 	/** Information about a collision between two physics objects. */
 	/** Information about a collision between two physics objects. */
 	struct CollisionData
 	struct CollisionData
 	{
 	{
-		Collider* colliderRaw; /**< Collider that was hit. */
+		Collider* collidersRaw[2]; /**< Colliders involved in the collision. */
 
 
 		/** 
 		/** 
-		 * Component of the collider that was hit. Can be null if collider is not owned by a component, in which case
-		 * use ::colliderRaw directly. 
+		 * Components of the colliders that were hit. Can be null if collider is not owned by a component, in which case
+		 * use ::collidersRaw directly. 
 		 */
 		 */
-		HCollider collider; 
+		HCollider collider[2]; 
 		// Note: Not too happy this is heap allocated, use static allocator?
 		// Note: Not too happy this is heap allocated, use static allocator?
-		Vector<ContactPoint> contactPoints; /**< Information about all the contact points for the hit */ 
+		Vector<ContactPoint> contactPoints; /**< Information about all the contact points for the hit. */ 
 	};
 	};
 
 
 	/** Determines what parent, if any, owns a physics object. */
 	/** Determines what parent, if any, owns a physics object. */

+ 9 - 6
BansheeCore/Source/BsCCharacterController.cpp

@@ -134,16 +134,12 @@ namespace BansheeEngine
 
 
 	void CCharacterController::onDestroyed()
 	void CCharacterController::onDestroyed()
 	{
 	{
-		// This should release the last reference and destroy the internal controller
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		destroyInternal();
 	}
 	}
 
 
 	void CCharacterController::onDisabled()
 	void CCharacterController::onDisabled()
 	{
 	{
-		// This should release the last reference and destroy the internal controller
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		destroyInternal();
 	}
 	}
 
 
 	void CCharacterController::onEnabled()
 	void CCharacterController::onEnabled()
@@ -184,6 +180,13 @@ namespace BansheeEngine
 		mInternal->setRadius(radius);
 		mInternal->setRadius(radius);
 	}
 	}
 
 
+	void CCharacterController::destroyInternal()
+	{
+		// This should release the last reference and destroy the internal controller
+		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
+		mInternal = nullptr;
+	}
+
 	void CCharacterController::triggerOnColliderHit(const ControllerColliderCollision& value)
 	void CCharacterController::triggerOnColliderHit(const ControllerColliderCollision& value)
 	{
 	{
 		// Const-cast and modify is okay because we're the only object receiving this event
 		// Const-cast and modify is okay because we're the only object receiving this event

+ 36 - 20
BansheeCore/Source/BsCCollider.cpp

@@ -89,26 +89,12 @@ namespace BansheeEngine
 
 
 	void CCollider::onDestroyed()
 	void CCollider::onDestroyed()
 	{
 	{
-		if (mParent != nullptr)
-			mParent->removeCollider(mThisHandle);
-
-		mParent = nullptr;
-
-		// This should release the last reference and destroy the internal collider
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		destroyInternal();
 	}
 	}
 
 
 	void CCollider::onDisabled()
 	void CCollider::onDisabled()
 	{
 	{
-		if (mParent != nullptr)
-			mParent->removeCollider(mThisHandle);
-
-		mParent = nullptr;
-
-		// This should release the last reference and destroy the internal collider
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		destroyInternal();
 	}
 	}
 
 
 	void CCollider::onEnabled()
 	void CCollider::onEnabled()
@@ -135,7 +121,7 @@ namespace BansheeEngine
 
 
 	void CCollider::setRigidbody(const HRigidbody& rigidbody, bool internal)
 	void CCollider::setRigidbody(const HRigidbody& rigidbody, bool internal)
 	{
 	{
-		SPtr<Rigidbody> rigidBodyPtr;
+		Rigidbody* rigidBodyPtr;
 
 
 		if (rigidbody != nullptr)
 		if (rigidbody != nullptr)
 			rigidBodyPtr = rigidbody->_getInternal();
 			rigidBodyPtr = rigidbody->_getInternal();
@@ -183,6 +169,18 @@ namespace BansheeEngine
 		updateTransform();
 		updateTransform();
 	}
 	}
 
 
+	void CCollider::destroyInternal()
+	{
+		if (mParent != nullptr)
+			mParent->removeCollider(mThisHandle);
+
+		mParent = nullptr;
+
+		// This should release the last reference and destroy the internal collider
+		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
+		mInternal = nullptr;
+	}
+
 	void CCollider::updateParentRigidbody()
 	void CCollider::updateParentRigidbody()
 	{
 	{
 		if (mIsTrigger)
 		if (mIsTrigger)
@@ -254,7 +252,13 @@ namespace BansheeEngine
 	{
 	{
 		// Const-cast and modify is okay because we're the only object receiving this event
 		// Const-cast and modify is okay because we're the only object receiving this event
 		CollisionData& hit = const_cast<CollisionData&>(data);
 		CollisionData& hit = const_cast<CollisionData&>(data);
-		hit.collider = mThisHandle;
+		hit.collider[0] = mThisHandle;
+
+		if(hit.collidersRaw[1] != nullptr)
+		{
+			CCollider* other = (CCollider*)hit.collidersRaw[1]->_getOwner(PhysicsOwnerType::Component);
+			hit.collider[1] = other->getHandle();
+		}
 
 
 		onCollisionBegin(hit);
 		onCollisionBegin(hit);
 	}
 	}
@@ -263,7 +267,13 @@ namespace BansheeEngine
 	{
 	{
 		// Const-cast and modify is okay because we're the only object receiving this event
 		// Const-cast and modify is okay because we're the only object receiving this event
 		CollisionData& hit = const_cast<CollisionData&>(data);
 		CollisionData& hit = const_cast<CollisionData&>(data);
-		hit.collider = mThisHandle;
+		hit.collider[0] = mThisHandle;
+
+		if (hit.collidersRaw[1] != nullptr)
+		{
+			CCollider* other = (CCollider*)hit.collidersRaw[1]->_getOwner(PhysicsOwnerType::Component);
+			hit.collider[1] = other->getHandle();
+		}
 
 
 		onCollisionStay(hit);
 		onCollisionStay(hit);
 	}
 	}
@@ -272,7 +282,13 @@ namespace BansheeEngine
 	{
 	{
 		// Const-cast and modify is okay because we're the only object receiving this event
 		// Const-cast and modify is okay because we're the only object receiving this event
 		CollisionData& hit = const_cast<CollisionData&>(data);
 		CollisionData& hit = const_cast<CollisionData&>(data);
-		hit.collider = mThisHandle;
+		hit.collider[0] = mThisHandle;
+
+		if (hit.collidersRaw[1] != nullptr)
+		{
+			CCollider* other = (CCollider*)hit.collidersRaw[1]->_getOwner(PhysicsOwnerType::Component);
+			hit.collider[1] = other->getHandle();
+		}
 
 
 		onCollisionEnd(hit);
 		onCollisionEnd(hit);
 	}
 	}

+ 12 - 9
BansheeCore/Source/BsCJoint.cpp

@@ -40,7 +40,7 @@ namespace BansheeEngine
 		{
 		{
 			Rigidbody* rigidbody = nullptr;
 			Rigidbody* rigidbody = nullptr;
 			if (value != nullptr)
 			if (value != nullptr)
-				rigidbody = value->_getInternal().get();
+				rigidbody = value->_getInternal();
 
 
 			mInternal->setBody(body, rigidbody);
 			mInternal->setBody(body, rigidbody);
 			updateTransform(body);
 			updateTransform(body);
@@ -130,16 +130,12 @@ namespace BansheeEngine
 		if (mBodies[1] != nullptr)
 		if (mBodies[1] != nullptr)
 			mBodies[1]->_setJoint(HJoint());
 			mBodies[1]->_setJoint(HJoint());
 
 
-		// This should release the last reference and destroy the internal joint
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		destroyInternal();
 	}
 	}
 
 
 	void CJoint::onDisabled()
 	void CJoint::onDisabled()
 	{
 	{
-		// This should release the last reference and destroy the internal joint
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		destroyInternal();
 	}
 	}
 
 
 	void CJoint::onEnabled()
 	void CJoint::onEnabled()
@@ -178,12 +174,12 @@ namespace BansheeEngine
 		Rigidbody* bodies[2];
 		Rigidbody* bodies[2];
 
 
 		if (mBodies[0] != nullptr)
 		if (mBodies[0] != nullptr)
-			bodies[0] = mBodies[0]->_getInternal().get();
+			bodies[0] = mBodies[0]->_getInternal();
 		else
 		else
 			bodies[0] = nullptr;
 			bodies[0] = nullptr;
 
 
 		if (mBodies[1] != nullptr)
 		if (mBodies[1] != nullptr)
-			bodies[1] = mBodies[1]->_getInternal().get();
+			bodies[1] = mBodies[1]->_getInternal();
 		else
 		else
 			bodies[1] = nullptr;
 			bodies[1] = nullptr;
 
 
@@ -197,6 +193,13 @@ namespace BansheeEngine
 		updateTransform(JointBody::B);
 		updateTransform(JointBody::B);
 	}
 	}
 
 
+	void CJoint::destroyInternal()
+	{
+		// This should release the last reference and destroy the internal joint
+		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
+		mInternal = nullptr;
+	}
+
 	void CJoint::notifyRigidbodyMoved(const HRigidbody& body)
 	void CJoint::notifyRigidbodyMoved(const HRigidbody& body)
 	{
 	{
 		// If physics update is in progress do nothing, as its the joint itself that's probably moving the body
 		// If physics update is in progress do nothing, as its the joint itself that's probably moving the body

+ 40 - 11
BansheeCore/Source/BsCRigidbody.cpp

@@ -330,19 +330,54 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
+	void CRigidbody::processCollisionData(CollisionData& data)
+	{
+		if (data.collidersRaw[0] != nullptr)
+		{
+			CCollider* other = (CCollider*)data.collidersRaw[0]->_getOwner(PhysicsOwnerType::Component);
+			data.collider[0] = other->getHandle();
+		}
+
+		if (data.collidersRaw[1] != nullptr)
+		{
+			CCollider* other = (CCollider*)data.collidersRaw[1]->_getOwner(PhysicsOwnerType::Component);
+			data.collider[1] = other->getHandle();
+		}
+	}
+
+	void CRigidbody::destroyInternal()
+	{
+		clearColliders();
+
+		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
+		mInternal = nullptr;
+	}
+
 	void CRigidbody::triggerOnCollisionBegin(const CollisionData& data)
 	void CRigidbody::triggerOnCollisionBegin(const CollisionData& data)
 	{
 	{
-		onCollisionBegin(data);
+		// Const-cast and modify is okay because we're the only object receiving this event
+		CollisionData& hit = const_cast<CollisionData&>(data);
+		processCollisionData(hit);
+
+		onCollisionBegin(hit);
 	}
 	}
 
 
 	void CRigidbody::triggerOnCollisionStay(const CollisionData& data)
 	void CRigidbody::triggerOnCollisionStay(const CollisionData& data)
 	{
 	{
-		onCollisionStay(data);
+		// Const-cast and modify is okay because we're the only object receiving this event
+		CollisionData& hit = const_cast<CollisionData&>(data);
+		processCollisionData(hit);
+
+		onCollisionStay(hit);
 	}
 	}
 
 
 	void CRigidbody::triggerOnCollisionEnd(const CollisionData& data)
 	void CRigidbody::triggerOnCollisionEnd(const CollisionData& data)
 	{
 	{
-		onCollisionEnd(data);
+		// Const-cast and modify is okay because we're the only object receiving this event
+		CollisionData& hit = const_cast<CollisionData&>(data);
+		processCollisionData(hit);
+
+		onCollisionEnd(hit);
 	}
 	}
 
 
 	void CRigidbody::onInitialized()
 	void CRigidbody::onInitialized()
@@ -352,18 +387,12 @@ namespace BansheeEngine
 
 
 	void CRigidbody::onDestroyed()
 	void CRigidbody::onDestroyed()
 	{
 	{
-		clearColliders();
-
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		destroyInternal();
 	}
 	}
 
 
 	void CRigidbody::onDisabled()
 	void CRigidbody::onDisabled()
 	{
 	{
-		clearColliders();
-
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		destroyInternal();
 	}
 	}
 
 
 	void CRigidbody::onEnabled()
 	void CRigidbody::onEnabled()

+ 1 - 1
BansheeCore/Source/BsCollider.cpp

@@ -41,7 +41,7 @@ namespace BansheeEngine
 		return mInternal->getIsTrigger();
 		return mInternal->getIsTrigger();
 	}
 	}
 
 
-	void Collider::setRigidbody(const SPtr<Rigidbody>& value)
+	void Collider::setRigidbody(Rigidbody* value)
 	{
 	{
 		mInternal->setIsStatic(value == nullptr);
 		mInternal->setIsStatic(value == nullptr);
 
 

+ 6 - 0
BansheePhysX/Include/BsPhysXCharacterController.h

@@ -9,6 +9,10 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	/** @addtogroup PhysX
+	 *  @{
+	 */
+
 	/** PhysX specific implementation if a CharacterController. */
 	/** PhysX specific implementation if a CharacterController. */
 	class PhysXCharacterController : public CharacterController
 	class PhysXCharacterController : public CharacterController
 								   , physx::PxUserControllerHitReport
 								   , physx::PxUserControllerHitReport
@@ -113,4 +117,6 @@ namespace BansheeEngine
 		float mMinMoveDistance = 0.0f;
 		float mMinMoveDistance = 0.0f;
 		float mLastMoveCall = 0.0f;
 		float mLastMoveCall = 0.0f;
 	};
 	};
+
+	/** @} */
 }
 }

+ 4 - 2
BansheePhysX/Source/BsPhysX.cpp

@@ -522,7 +522,8 @@ namespace BansheeEngine
 
 
 		for(auto& entry : mTriggerEvents)
 		for(auto& entry : mTriggerEvents)
 		{
 		{
-			data.colliderRaw = entry.other;
+			data.collidersRaw[0] = entry.trigger;
+			data.collidersRaw[1] = entry.other;
 
 
 			switch (entry.type)
 			switch (entry.type)
 			{
 			{
@@ -541,7 +542,8 @@ namespace BansheeEngine
 		auto notifyContact = [&](Collider* obj, Collider* other, ContactEventType type, 
 		auto notifyContact = [&](Collider* obj, Collider* other, ContactEventType type, 
 			const Vector<ContactPoint>& points, bool flipNormals = false)
 			const Vector<ContactPoint>& points, bool flipNormals = false)
 		{
 		{
-			data.colliderRaw = other;
+			data.collidersRaw[0] = obj;
+			data.collidersRaw[1] = other;
 			data.contactPoints = points;
 			data.contactPoints = points;
 
 
 			if(flipNormals)
 			if(flipNormals)