Hi,
I have a problem. My GameObject.SendMessage in OnCollisionEnter() fails to work after restart, but not globally, just for one class that calls it. It worked like for several months of development, then stopped. I don’t know where to look for a bug. Any ideas? Thanks in advance.
Try posting your code.
I’ve tried to change SendMessage to direct call - it fails as well. I seem to be losing reference, am I?
Here I send…
public virtual void OnCollisionEnter (Collision collision)
{
if (mHitMode == HitMode.Collision)
{
if (IsTargetMatchingFilter(collision.collider.gameObject))
{
if (!mHasCollided && mLastCollidedObject != collision.collider.gameObject)
{
mHasCollided = true;
mLastCollidedObject = collision.collider.gameObject;
//raise event -- target hit by source
Event_WeaponHitTarget eventWeaponHitTarget = new Event_WeaponHitTarget(mDamageDealt);
eventWeaponHitTarget.mTargetObject = collision.collider.gameObject;
eventWeaponHitTarget.mSourceObject = this.gameObject;
Events.instance.Raise(eventWeaponHitTarget);
Debug.Log ("WeaponBase OnCollisionEnter if (mHitMode == HitMode.Collision) BEFORE OnHit");
OnHit(collision.collider.gameObject);
if (mUseEventSoundsCollision)
{
Event_Sound eventSound = new Event_Sound ();
eventSound.mPos = transform.position;
eventSound.mSoundType = SoundType.ProjectileCollision;
eventSound.m2D = false;
eventSound.mSoundLooping = false;
Events.instance.Raise (eventSound);
}
}
}
}
if (mUseLight && mLightUpOnCol && mLight != null)
StartCoroutine (LightUpLightOnCol(mLightUpTime));
}
and here I receive…
public void ChangeHealth(float mDamageTaken)
{
Debug.Log ("Character ChangeHealth NAME " + gameObject.name);
if (!mIsTalking)
{
if (Mathf.Abs(mDamageTaken) > 0f && GetState() != State.Dead)
{
// print ("character " + this.gameObject.name + " took " + mDamageTaken + " damage.");
mHitsReceived++;
mTimeSinceLastHit = 0f;
//we dont want to retrigger anims once show anim of hit - we count dam, but not trigger anim
if (GetState() != State.GotHit && GetState() != State.GotHitPending && GetState() != State.GotHitSeriously)
{
if (IsHitSeriously())
{
SetState (State.GotHitSeriously);
}
else
{
SetState (State.GotHit);
}
}
mHitPointsBeforeDeath = mHitPoints;
Debug.Log ("Char " + gameObject.name + " ChangeHealth mHitPoints BEFORE hit " + mHitPoints);
mHitPoints += mDamageTaken * mDamageTakenMultiplier * mNonHitZoneDamMult;
Debug.Log ("Char " + gameObject.name + " ChangeHealth mHitPoints AFTER hit " + mHitPoints);
//show hitPointUI if enabled
if (mShowHitPointUI)
{
ShowHitPointUI(mDamageTaken);
}
// If the health runs out, then Die.
if (mHitPoints <= 0 && !mIsDead && mIsDestructible && GetState() != State.Dead)
Die();
// Make sure that the health never exceeds the maximum health
if (mHitPoints > mHitPointsInitial)
mHitPoints = mHitPointsInitial;
//reset damage taken
mDamageTaken = 0f;
}
}
}
I am using U 5.4.0f3 and the old way of restarting a scene by Application.LoadLevel()
I found the source, thanks! It was a lack of null check in a seemingly unrelated script that handled the UI of a super-state.
1 Like