Results 1 to 9 of 9
  1. #1

    Lightbulb Displaying Something on the HUD When a Trigger is Touched

    There are a number of ways you could display something on the player's HUD when they touch a trigger in the level. Using Kismet only is one possible approach, but not really the best choice.

    One way I would approach it would be to create a custom trigger object in UnrealScript (which you can place in the level) that fires off a function in the touching player's PlayerController class. This function would in turn fire off a function in the HUD class, which will then update the player's HUD.

    You'll need to make a new class that extends Trigger (C:\UDK\UDK-2011-09\Development\Src\Engine\Classes\Trigger.uc)

    Here's an example implementation:

    Trigger Class

    Code:
    class MyTrigger extends Trigger
    	placeable
    	ClassGroup(Common);
    
    event Touch(Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal)
    {
        local Pawn TouchingPawn;
        local MyPlayerController PC;
    	
        TouchingPawn = Pawn(Other);
        PC = MyPlayerController(TouchingPawn.Controller);
    
        `log(Self$" was touched!");
        `log("Touched by: " @ Other); // logs the pawn that touched it
        `log(Other @ " is possessed by: " @ PC); // logs the player controller that possesses the pawn.
    
        PC.TriggerTouched(); // this executes the TriggerTouched() function in the PlayerController class.
    }
    MyPlayerController should be replaced with the name of your PlayerController class.




    PlayerController Class

    Your PlayerController next fires off a function in the HUD. There are two ways to do this.

    Version 1

    In version 1, simply make a direct call to the HUD's functions with this format:

    Code:
    function TriggerTouched()
    {
        MyHUDWrapper(myHUD).HudMovie.DoSomething();
    }
    MyHUDWrapper should be replaced with the name of your HUD Wrapper class (which extends UTHUDBase)
    HudMovie should be replaced with the name of the instantiated HUD, as created by the HUD Wrapper.


    Version 2

    In version 2, we first add a function to register the HUD in the PlayerController:

    Code:
    var MyHudClass MyHud;
    
    function registerHUD(MyHudClass hud)
    {
        RegisteredHud = hud;
    }
    Now, you can add the function to call in your PlayerController, when the trigger is touched:

    Code:
    function TriggerTouched()
    {
        RegisteredHud.DoSomething();
    }



    HUD Class

    (Version 2 only) In your HUD class, call the function registerHUD() in the Init()/Start() function:

    Code:
    var MyPlayerController PC;
    
    PC = MyPlayerController(GetPC());
    PC.registerHUD(self);
    And finally, your HUD would have the function to do something visibly:

    Code:
    function DoSomething()
    {
        \\ do something in the HUD...
    }
    Last edited by Matt Doyle; 10-17-2011 at 03:24 PM.

  2. #2

    Default

    Are you registering the GFxMovie or the wrapper class in Version 2? The RegisterHud() function in PC takes the wrapper class while you pass in a GFxMovie into this function in your HUD class example (GetPC() doesn't exist in the wrapper)

  3. #3
    Iron Guard
    Join Date
    Nov 2009
    Posts
    565

    Default

    Hello, can this be used to display a warning message in game for example?

  4. #4

    Default

    @Snufkin
    Yes, it can be used for pretty much anything.

  5. #5
    Palace Guard

    Join Date
    Jun 2007
    Location
    Christchurch
    Posts
    3,781

    Default

    Well, a more straight forward method may be to just do it all in this Trigger class.

    Code:
    class MyTrigger extends Trigger
    	placeable
    	ClassGroup(Common);
    
    event Touch(Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal)
    {
        local Pawn TouchingPawn;
        local MyPlayerController PC;
        local MyHUD HUD;
    	
        TouchingPawn = Pawn(Other);
        if (TouchingPawn != None)
        {
            PC = MyPlayerController(TouchingPawn.Controller);
            if (PC != None)
            {
                HUD = MyHUD(PC.MyHUD);
                if (HUD != None && HUD.HUDMovie != None)
                {
                    HUD.HUDMovie.DoSomething();
                }
            }
        }
    }

  6. #6

    Default

    No doubt there are many ways it could be done. Thanks for the addition.

  7. #7
    Skaarj
    Join Date
    Jul 2011
    Location
    Louisiana, USA
    Posts
    10

    Default

    I am fairly new to UnrealScript so I apologize in advance for the basic question. How can I determine which trigger is being touched in order to update the HUD appropriately?

    Thanks in advance!

  8. #8
    MSgt. Shooter Person
    Join Date
    May 2011
    Posts
    34

    Default

    This custom trigger you place in the map just like any other trigger in the Actor Browser, if a pawn touches the trigger it will launch
    a function in the pawns HUD. Hope this answer helps out

  9. #9
    MSgt. Shooter Person
    Join Date
    Feb 2012
    Posts
    62

    Default

    Quick question:

    I tried something different from code below, but my log gives me an error in DoSomething () from type Canvas (I used Canvas to draw a basic Message on my Screen).

    So the question is: Is it possible to call the Canvas class in my DoSometthing() function without any call in DrawHUD or is it only possible to use this class in PostRender() and DrawHUD()?


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.