Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

in unreal 5 blueprints I have made an event that when you press a button time slows down…

  1. User

    in unreal 5 blueprints I have made an event that when you press a button time slows down using time dilation and if you press it again time would resume to normal speed now i want to add a duration to it so that after 2 seconds time goes to normal speed automatically and something like a power bar fills up when you are not using slow time and it goes down again in that 2 seconds when you are using it

  2. Assistant

    Sure! In Unreal Engine 5 Blueprints, you can achieve this by using timers and variables to keep track of the power bar and the time-based slowdown. Here's a step-by-step approach:

    1. Setup Variables:

      • bIsTimeSlowed: Boolean to check whether time is currently slowed.
      • SlowTimeDuration: Float to store the duration of the slow time (e.g., 2 seconds).
      • PowerBarValue: Float to store the power bar's current value.
      • MaxPowerBarValue: Float to store the maximum value of the power bar (e.g., 100).
      • PowerBarRechargeRate: Float to determine how fast the power bar refills.
    2. Button Press Logic:

      • On button press, check if bIsTimeSlowed is false.
        • If false, activate slow time by setting time dilation, setting bIsTimeSlowed to true, and starting a timer for the duration.
        • If true, set time dilation back to normal and set bIsTimeSlowed to false.
    3. Timer Logic:

      • When the timer expires (after 2 seconds), set time dilation back to normal and set bIsTimeSlowed to false.
    4. Power Bar Logic:

      • When time is slowed (bIsTimeSlowed is true), decrease PowerBarValue over time.
      • When time is normal, increase PowerBarValue over time until it reaches MaxPowerBarValue.

    Here's an example Blueprint logic:

    Step 1: Create Variables

    In your Blueprint (for example, in the Character Blueprint):

    1. Create the following variables:
      • bIsTimeSlowed (Boolean)
      • SlowTimeDuration (Float, default 2.0)
      • PowerBarValue (Float, default 100.0)
      • MaxPowerBarValue (Float, default 100.0)
      • PowerBarRechargeRate (Float, default 10.0)

    Step 2: Button Press Logic

    In the Event Graph of your Blueprint:

    1. Create an input event for the button press (e.g., InputAction SlowTime).
    2. Add a branch node (If statement) to check the bIsTimeSlowed variable.
    3. If bIsTimeSlowed is false:
      • Set Global Time Dilation (Set to a slower value, e.g., 0.2).
      • Set bIsTimeSlowed to true.
      • Set Timer by Function Name (Create a custom event to handle the timer's completion).
    4. If bIsTimeSlowed is true:
      • Set Global Time Dilation to 1.0 (normal speed).
      • Set bIsTimeSlowed to false.
      • Clear the timer.

    Step 3: Timer Logic

    Create a custom event (e.g., OnTimeDilationEnd) to handle when the timer ends:

    1. Reset Global Time Dilation to 1.0 (normal speed).
    2. Set bIsTimeSlowed to false.

    Step 4: Power Bar Logic

    In the Event Graph:

    1. Use the Event Tick node to update the power bar value each frame.
    2. Add a branch to check the value of bIsTimeSlowed.
    3. If bIsTimeSlowed is true:
      • Decrease PowerBarValue based on the delta time and some depletion rate (e.g., PowerBarValue -= DeltaTime * DepletionRate).
    4. If bIsTimeSlowed is false:
      • Increase PowerBarValue based on the delta time and PowerBarRechargeRate (e.g., PowerBarValue += DeltaTime * PowerBarRechargeRate).
      • Clamp PowerBarValue so it doesn't exceed MaxPowerBarValue.

    Example Blueprint Nodes:

    Event Tick
    |-> Branch (Condition: `bIsTimeSlowed`)
        |-> True:    `PowerBarValue` -= `DeltaTime * DepletionRate`
        |-> False:   `PowerBarValue` += `DeltaTime * PowerBarRechargeRate`
                    |-> Clamp (`PowerBarValue`, 0, `MaxPowerBarValue`)
    

    Example Button Press Event:

    InputAction SlowTime
    |-> Branch (Condition: `bIsTimeSlowed`)
        |-> True
        |      |-> Set Global Time Dilation 1.0
        |      |-> Set `bIsTimeSlowed` False
        |      |-> Clear Timer
        |-> False
               |-> Set Global Time Dilation 0.2
               |-> Set `bIsTimeSlowed` True
               |-> Set Timer by Function Name (Function Name: OnTimeDilationEnd, Time: `SlowTimeDuration`)
    

    Example Timer Expiry Event:

    Custom Event: OnTimeDilationEnd
    |-> Set Global Time Dilation 1.0
    |-> Set `bIsTimeSlowed` False
    

    This setup will ensure that the slow time mechanic works, automatically reverts after 2 seconds, and includes a power bar that depletes and refills accordingly.

  3. User

    explain in detail how to implement this

  4. Assistant

    Certainly! Below is a step-by-step guide to implementing the described behavior in Unreal Engine 5 using Blueprints.

    Step 1: Create Variables

    1. Open your blueprint (e.g., Character Blueprint).
    2. In the Variables panel, click the "+" button to add new variables:
      • bIsTimeSlowed (Boolean, default: False)
      • SlowTimeDuration (Float, default: 2.0)
      • PowerBarValue (Float, default: 100.0)
      • MaxPowerBarValue (Float, default: 100.0)
      • PowerBarRechargeRate (Float, default: 10.0)
      • DepletionRate (Float, default: 50.0) (to determine how fast the power bar depletes)

    Step 2: Button Press Logic

    1. In the Event Graph, add an Input Action node for the button press (e.g., InputAction SlowTime). If you don't have an Input Action setup, you can set it in the Project Settings under Input.
    2. Drag out a wire from the Pressed pin of the Input Action node and add a Branch node.
    3. Drag the bIsTimeSlowed variable and hook it up to the Condition input of the Branch node.
    4. From the True branch (i.e., if bIsTimeSlowed is true):
      • Add a Set Global Time Dilation node and set its Time Dilation to 1.0 (normal speed).
      • Add a Set node to set bIsTimeSlowed to false.
      • Add a Clear Timer node to clear the timer.
    5. From the False branch (i.e., if bIsTimeSlowed is false):
      • Add a Set Global Time Dilation node and set its Time Dilation to a slow value (e.g., 0.2).
      • Add a Set node to set bIsTimeSlowed to true.
      • Add a Set Timer by Function Name node:
        • Set the Function Name to the name of the custom event you're going to create (e.g., OnTimeDilationEnd).
        • Set the Time to the value of the SlowTimeDuration variable.
        • Ensure Looping is unchecked.

    Blueprint for Button Press Event:

    InputAction SlowTime
    |-> Branch
        |-> Condition: bIsTimeSlowed
            |-> True
            |      |-> Set Global Time Dilation to 1.0
            |      |-> Set bIsTimeSlowed to False
            |      |-> Clear Timer
            |-> False
                   |-> Set Global Time Dilation to 0.2
                   |-> Set bIsTimeSlowed to True
                   |-> Set Timer by Function Name (Function Name: OnTimeDilationEnd, Time: SlowTimeDuration)
    

    Step 3: Timer Logic

    1. In the Event Graph, add a Custom Event node (e.g., OnTimeDilationEnd).
    2. From the OnTimeDilationEnd node:
      • Add a Set Global Time Dilation node and set its Time Dilation to 1.0.
      • Add a Set node to set bIsTimeSlowed to false.

    Blueprint for Timer Expiry Event:

    Custom Event: OnTimeDilationEnd
    |-> Set Global Time Dilation to 1.0
    |-> Set bIsTimeSlowed to False
    

    Step 4: Power Bar Logic

    1. In the Event Graph, add an Event Tick node.
    2. Drag out a wire from the Tick pin and add a Branch node.
    3. Drag the bIsTimeSlowed variable and hook it up to the Condition input of the Branch node.
    4. From the True branch:
      • Add a Set node to decrease PowerBarValue over time:
        • PowerBarValue -= DeltaTime * DepletionRate (use Float - Float and Float * Float nodes to calculate this).
    5. From the False branch:
      • Add a Set node to increase PowerBarValue over time:
        • PowerBarValue += DeltaTime * PowerBarRechargeRate.
      • Add a Clamp node to ensure PowerBarValue does not exceed MaxPowerBarValue:
        • Clamp (float) node with Min=0, Max=MaxPowerBarValue.

    Blueprint for Power Bar Logic (Tick Event):

    Event Tick
    |-> Branch
        |-> Condition: bIsTimeSlowed
            |-> True
            |    |-> Set PowerBarValue to PowerBarValue - (DeltaTime * DepletionRate)
            |-> False
                 |-> Set PowerBarValue to PowerBarValue + (DeltaTime * PowerBarRechargeRate)
                 |-> Clamp (PowerBarValue) (Min: 0, Max: MaxPowerBarValue)
    

    By following these steps, you should have a working setup in Unreal Engine 5 Blueprints where pressing a button slows down time for 2 seconds, and a power bar depletes while time is slowed and refills when it is not.

  5. User

    what should i plug to the context pin of delta time

  6. Assistant

    In an Unreal Engine blueprint, you don't directly plug anything into a "context" pin for DeltaTime. Rather, you use a node called Get World Delta Seconds to get the time elapsed between the current and previous tick, which is what you typically use to scale changes that are happening every frame.

    Here's a more detailed explanation and example of how to implement the Event Tick logic, including the use of Get World Delta Seconds:

    Detailed Event Tick Logic

    1. Add the Event Tick Node:

      • In your blueprint's Event Graph, add an Event Tick node. This node executes every frame.
    2. Add the Branch Node:

      • From the Event Tick node, drag out a wire and add a Branch node.
      • Connect the bIsTimeSlowed variable to the Condition pin of the Branch node.
    3. Handling the True Branch (Time is Slowed):

      • From the True output pin of the Branch node, drag out a wire and add a Get World Delta Seconds node. This node will provide the time elapsed since the last frame, which allows us to scale our values correctly.
      • Drag out another wire from the True pin and add a Set node to update the PowerBarValue.
      • Use Float - Float and Float * Float nodes to calculate the new PowerBarValue as follows:
        • PowerBarValue - (DeltaTime * DepletionRate)
    4. Handling the False Branch (Time is Normal):

      • From the False output pin of the Branch node, drag out a wire and add a Get World Delta Seconds node.
      • Drag out another wire from the False pin and add a Set node to update the PowerBarValue.
      • Use Float + Float and Float * Float nodes to calculate the new PowerBarValue as follows:
        • PowerBarValue + (DeltaTime * PowerBarRechargeRate)
      • Add a Clamp (Float) node to ensure the PowerBarValue stays within specified bounds.
        • Set Min to 0 and Max to MaxPowerBarValue.

    Example Blueprint for Event Tick Logic

    Event Tick
    |-> Branch
        |-> Condition: bIsTimeSlowed
            |-> True
            |    |-> Get World Delta Seconds -> DeltaTime
            |    |-> Set PowerBarValue
            |        |-> PowerBarValue - (DeltaTime * DepletionRate)
            |
            |-> False
            |    |-> Get World Delta Seconds -> DeltaTime
            |    |-> Set PowerBarValue
            |        |-> PowerBarValue + (DeltaTime * PowerBarRechargeRate)
            |        |-> Clamp (Min: 0, Max: MaxPowerBarValue)
    

    Steps to Add and Connect Nodes:

    1. Add Event Tick:

      • Right-click in the Event Graph and search for Event Tick.
    2. Add Branch Node:

      • Drag from the Event Tick pin and search for Branch.
      • Connect the Boolean variable (bIsTimeSlowed) to the Condition pin of the Branch.
    3. Add Get World Delta Seconds Nodes:

      • Drag from the True and False pins of the Branch separately, and search for Get World Delta Seconds.
    4. Add Set Nodes:

      • Drag from the True and False pins of the Branch, after the Get World Delta Seconds nodes, and search for Set.
      • Select PowerBarValue as the variable to set.
    5. Add Arithmetic Nodes:

      • To subtract in the True branch:
        • Drag from the DeltaTime output pin of Get World Delta Seconds and search for * (float). Set the other input pin to DepletionRate.
        • Drag from the result and search for - (float). Connect PowerBarValue to the top input.
      • To add in the False branch:
        • Drag from the DeltaTime output pin of Get World Delta Seconds and search for * (float). Set the other input pin to PowerBarRechargeRate.
        • Drag from the result and search for + (float). Connect PowerBarValue to the top input.
    6. Add Clamp Node:

      • For the False branch, drag from the resulting value (PowerBarValue + (DeltaTime * PowerBarRechargeRate)) and search for Clamp (float).
      • Set Min to 0 and Max to your MaxPowerBarValue.

    By following these steps and connecting the nodes as described, you ensure that the PowerBarValue is correctly updated each frame based on whether time is slowed down or normal. This setup will work smoothly within the game loop, accurately reflecting the player's usage and replenishment of the slow time ability.