Creating An Interaction From A PlayerController
Interactions created from a PlayerController are much simpler than those created from mutators. You only need to add a small amount of code, and a variable.
First off, add a variable - bHasInteraction (you dont want to give a player several interactions):
var bool bHasInteraction
Next, you will need to edit the state "PlayerWaiting". Add a "Begin:" label (if you dont already have one), and add this code under it.
Begin: If ((Viewport(Player) != None) && (!bHasInteraction)) { Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", Player); bHasInteraction = True; }
.. and that's it.
Make sure you don't try to add an interaction within PostBeginPlay(). It won't work because Player is None.
Interactions can do a whole load of stuff though, so choose a section relating to what you want to do:
Comments
Will: Any problems understanding this? Anything I could do to make it clearer? If so: tell me, or do it yourself
VonStrohmen: I tried using this procedure, but for some reason an InteractionMaster isn't spawned for my player controller. My player controller is always a spectator, if that makes a difference, and I check for PlayerController.Player.InteractionMaster every 2 seconds using a timer. The player is created, but the InteractionMaster isn't for some reason. I thought this might have to do with the fact that the player controller is always a spectator: any suggestions?
MasterOfTheDark: I had the same problem as VonStrohmen, and I used this code instead to add the interaction: ¶
function EnterStartState() { Super.EnterStartState(); if ((Viewport(Player) != None) && (!bHasInteraction)) { Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", Player); bHasInteraction = True; } }
The code written by Will might work in previous versions of Unreal, but this is what is necessary for UT2003. (Oh, and I checked it for net play. It works there, too.)
Wormbo: There are no Interactions in previous engine versions...