Legacy:Creating An Interaction From A PlayerController

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to navigation Jump to search

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):

<uscript> var bool bHasInteraction </uscript>

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.

<uscript> Begin: If ((Viewport(Player) != None) && (!bHasInteraction)) { Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", Player); bHasInteraction = True; } </uscript>

.. 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: ΒΆ

<uscript> function EnterStartState() { Super.EnterStartState(); if ((Viewport(Player) != None) && (!bHasInteraction)) { Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", Player); bHasInteraction = True; } } </uscript>

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... ;)

RegularX: "you dont want to give a player several interactions" <– why is that? It can't juggle them?

Mychaeel: There's no technical problem with having several Interactions stacked. I think what's meant there is "You don't want to accidentally give a player several instances of the same Interaction" if that code happens to be executed several times.

RegularX: That's what I suspected. Question though - interactions I assume are client side only. Does this mean that any config vars they use are based on the local client and not the server (unless otherwise replicated)? I did some tests last night and that seemed to be true, but I remember similar things being much, much harder in Freehold UT to get the same effect (variables from a client machine valid online)

Mysterial: Values of config properties are taken from the machine they are spawned on (in this case, the client). Additionally, for replicated actors, as far as the server is concerned the properties have their default values, so changes in configuration will NOT be automatically replicated - you will either have to set a seperate property in an initialization function (e.g. PostBeginPlay()) or use replicated functions (PlayerController in particular uses this to inform the server of various clientside settings)