From f7de5d46bedbbc822fc58a9dd4d4c7f7060fc9f6 Mon Sep 17 00:00:00 2001 From: Mustafa Alperen Seki Date: Sat, 23 Dec 2017 15:25:10 +0300 Subject: [PATCH] Allow GrantConditionOnPrerequisite to work on Player: --- .../Traits/Conditions/GrantConditionOnPrerequisite.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs index 6f1394b25e..887c39bbdd 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs @@ -41,11 +41,17 @@ namespace OpenRA.Mods.Common.Traits public GrantConditionOnPrerequisite(Actor self, GrantConditionOnPrerequisiteInfo info) { this.info = info; - globalManager = self.Owner.PlayerActor.Trait(); } void INotifyCreated.Created(Actor self) { + // Special case handling is required for the Player actor. + // Created is called before Player.PlayerActor is assigned, + // so we must query other player traits from self, knowing that + // it refers to the same actor as self.Owner.PlayerActor + var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor; + + globalManager = playerActor.Trait(); conditionManager = self.TraitOrDefault(); }