When we test our game on android phones, it sometimes throws NullReferenceException in this function, maybe once in ten times:
public void AddEventSwitchOwner(int slotID)
{
ViewEventSwitchOwner viewEvent = gameObject.AddComponent<ViewEventSwitchOwner>();
viewEvent.Init(this, slotID);
AddEvent (viewEvent);
}
And the output log is:
05-14 16:58:56.645: I/Unity(31355): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 53)
05-14 16:58:56.765: I/Unity(31355): NullReferenceException
05-14 16:58:56.765: I/Unity(31355): at UnityEngine.Component.get_gameObject () [0x00000] in <filename unknown>:0
05-14 16:58:56.765: I/Unity(31355): at AsgardGame.FengShen.ViewManager.AddEventSwitchOwner(Int32 slotID) [0x00000] in <filename unknown>:0
05-14 16:58:56.765: I/Unity(31355): at (wrapper delegate-invoke) System.Action`1<int>:invoke_void__this___int (int)
05-14 16:58:56.765: I/Unity(31355): at AsgardGame.FengShen.LogicManager.SendSwitchOwnerEvent (Int32 slotID) [0x00000] in <filename unknown>:0
05-14 16:58:56.765: I/Unity(31355): at AsgardGame.FengShen.LogicCardAbilityBuff018.SwitchOwner () [0x00000] in <filename unknown>:0
05-14 16:58:56.765: I/Unity(31355): at AsgardGame.FengShen.LogicCardAbilityBuff018.AttachBuff (AsgardGame.FengShen.LogicCardCreature target) [0x00000] in <filename unknown>:0
05-14 16:58:56.765: I/Unity(31355): at AsgardGame.FengShen.LogicCardAbility018.ApplyInAbility (AsgardGame.FengShen.LogicCardCreature targetCreature) [0x00000] in <filename unknown>:0
05-14 16:58:56.765: I/Unity(31355): at AsgardGame.FengShen.LogicManager.ApplyOperateInAbility (Int32 slotIdx) [0x00000] in <filename unknown>:0
05-14 16:58:56.765: I/Unity(31355): at AsgardGame.FengShen.LogicManager.ApplyOperateCardInAbility (Int32 slotIdx) [0x00000] in <filename unkn
Which I think is very wield, I mean, its accessing its own gameObject! how can it be null?
Is it possible when player left the scene, the gameobject is destroyed , but its component continue exist, so when he come back to the scene again, this script’s gameObject is null?