AnyRPGCore icon indicating copy to clipboard operation
AnyRPGCore copied to clipboard

null reference in update status

Open michaelday008 opened this issue 2 years ago • 0 comments

Describe the bug NullReferenceException: Object reference not set to an instance of an object AnyRPG.TradeSkillPrerequisite.UpdateStatus (System.Boolean notify) (at Assets/AnyRPG/Core/System/Scripts/Quest/TradeSkillPrerequisite.cs:28)

To Reproduce Steps to reproduce the behavior:

  1. set any trade skill to auto-learn
  2. use the new game window and have any unit spawn in unit preview mode

Expected behavior no error

Additional context The exact issue happens on line 27 of trade skill prerequisite

bool checkResult = playerManager.MyCharacter.CharacterSkillManager.HasSkill(prerequisiteSkill);

When a unit preview spawns, the player character is not spawned yet, so the reference is null.

Possible solutions

  • wrap these types of checks in if-then statement to prevent null reference
  • drop support for players in the scene not spawned through unit spawn nodes. This prevents the automatic setting of unit type to AI in this case.
  • only auto-learn skills if the player type is the actual player character. This requires testing to ensure that code that sets unit profile type to player is not re-triggered at any point.

michaelday008 avatar Feb 12 '23 06:02 michaelday008