vectorfrog
Member
I have a character selection scene that instantiates a character just fine. I have this character set to not destroy on load. I then load the main game scene and have the camera find the character. This works. Things break when trying to setup the crosshairs monitor and slot 0 monitor. After some debugging, I found that Awake is not being called in CrosshairsMonitor.cs at all in this case for some reason. If I put the code that is currently in Awake into OnEnable, then the problem goes away, kind of. I'm not sure if this is the best approach since I'm still learning the UCC stuff. The exception that I am getting is:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Utility.UnityEngineUtility.SizeSprite (UnityEngine.Sprite sprite, UnityEngine.RectTransform spriteRectTransform) (at Assets/Opsive/UltimateCharacterController/Scripts/Utility/UnityEngineUtility.cs:106)
Opsive.UltimateCharacterController.UI.CrosshairsMonitor.OnEquipItem (Opsive.UltimateCharacterController.Items.Item item, System.Int32 slotID) (at Assets/Opsive/UltimateCharacterController/Scripts/UI/CrosshairsMonitor.cs:336)
There is a couple more lines to this stack trace, but this is the important part of it.
I found that on line 336 in CrosshairsMonitor.cs, m_CenterRectTransform is the culprit and is null when passed to the SizeSprite method. This is because Awake doesn't get called. I've put a breakpoint in there and it doesn't get hit.
If I put the code that is in Awake in OnEnable this problem goes away. If I try the same fix for the SlotItemMonitor.cs, it doesn't work. Awake is called in that class just fine, so I'm not sure yet what the problem is there.
I'm hoping Justin or someone with some intimate knowledge of UCC can help me out with this. I also want to mention that if I instantiate a character in the main game scene hierarchy then things work just fine. It is only when I have a character instantiated already when I load the game scene, AND the character has a weapon equipped, including the Body item for melee.
I'd also like to mention that if I don't give the character any weapons and instantiate it like I am doing in the previous scene, then things work just fine. I have yet to see if picking up a weapon after this breaks anything, but I don't think it will. It's only when the character starts out with a weapon and is instantiated in the previous screen.
Any help would be greatly appreciated.
Thanks!
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Utility.UnityEngineUtility.SizeSprite (UnityEngine.Sprite sprite, UnityEngine.RectTransform spriteRectTransform) (at Assets/Opsive/UltimateCharacterController/Scripts/Utility/UnityEngineUtility.cs:106)
Opsive.UltimateCharacterController.UI.CrosshairsMonitor.OnEquipItem (Opsive.UltimateCharacterController.Items.Item item, System.Int32 slotID) (at Assets/Opsive/UltimateCharacterController/Scripts/UI/CrosshairsMonitor.cs:336)
There is a couple more lines to this stack trace, but this is the important part of it.
I found that on line 336 in CrosshairsMonitor.cs, m_CenterRectTransform is the culprit and is null when passed to the SizeSprite method. This is because Awake doesn't get called. I've put a breakpoint in there and it doesn't get hit.
If I put the code that is in Awake in OnEnable this problem goes away. If I try the same fix for the SlotItemMonitor.cs, it doesn't work. Awake is called in that class just fine, so I'm not sure yet what the problem is there.
I'm hoping Justin or someone with some intimate knowledge of UCC can help me out with this. I also want to mention that if I instantiate a character in the main game scene hierarchy then things work just fine. It is only when I have a character instantiated already when I load the game scene, AND the character has a weapon equipped, including the Body item for melee.
I'd also like to mention that if I don't give the character any weapons and instantiate it like I am doing in the previous scene, then things work just fine. I have yet to see if picking up a weapon after this breaks anything, but I don't think it will. It's only when the character starts out with a weapon and is instantiated in the previous screen.
Any help would be greatly appreciated.
Thanks!
Last edited: