In my game, I have a class with a method called by an Equipment.SimpleChanged callback. In this script, I check which items are equipped/unequipped and from which body parts, so that I can apply special rules in some cases. One issue I have is when I want to unequip an equipment from an equipment part (let's say, remove a sword from a scabbard equipment part) and then equip this equipment (e.g. sword) in another equipment part (e.g. right hand). To achieve this, I need to first unequip the sword from the scabbard to the inventory, then wait one frame (Time.deltaTime), then equip the sword from the inventory to the right hand. In a coroutine, I use:
combatant.Equipment.UnequipAccess(scabbardWeapon, combatant);
yield return new WaitForSeconds(Time.deltaTime);
combatant.Equipment.EquipAccess(rightHandEquipmentPartID, scabbardWeapon, combatant, combatant, true);
If I don't use the yield return line, the sword is removed from the scabbard, but it is not put in the right hand.

Is there a way to do that in the same frame?

Also, I'd like to know what is the difference between the EquipAccess and the Equip functions and what does the "bool reset" parameter mean in these functions.

Thanks!
  • The access functions route the calls via the access handler, but ultimately call the non-access functions. So, unless you're using (or planning to use) the access handler, you don't need to use the access functions.

    You shouldn't need to wait a frame, e.g. the Switch Equipment node does pretty much the same and doesn't wait for a frame.
    My guess would be that due to your listening to equipment changes, the unequip already calls it again, possible interfering with what you're doing. Try unsubscribing from the SimpleChanged event handler while doing equipment changes.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks for the precision concerning the Access Handler. Might be useful later!

    I will try unsubscribing from the event handler as you suggest.

    Concerning the Reset parameter of the Equip function, could you please explain it's use?

    Thanks!
  • If reset is passed on as true, the combatant's status will be recalculated after the equipment change - which is needed for the changes to reflect on the stats.

    If you're changing multiple equipment, you could pass on false and only reset for the last equip (or manually call it via combatant.Status.ResetStatus(true)). Although that might lead to wrong equip requirements, as the status isn't updated between equipment changes.
    Generally, I'd recommend just passing on true here :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.