tutorials header image

Creating an Advanced Security System in UEFN

tutorials• by BizaNator

Building an Advanced Security System in UEFN

Today we'll create a fully functional security system that can detect players, trigger alarms, activate defense turrets, and create security barriers. This tutorial will demonstrate how to combine multiple devices and create clean, modular code in Verse.

Part 1: Understanding the Components

First, let's break down the devices we'll be using:

  • perception_trigger_device: Acts as our security camera/motion detector
  • customizable_light_device: Visual alarm indicator
  • automated_turret_device: Security response system
  • audio_player_device: Alarm sound effects
  • barrier_device: Security lockdown system

Part 2: Basic Structure Setup

Let's start by creating our main security system class and setting up our device variables:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

# Security system that manages detection and response
security_system_device := class(creative_device):
    # Detection device that acts as our motion sensor
    var Detector : perception_trigger_device = perception_trigger_device{}
    
    # Alarm light that activates when system is triggered
    var AlarmLight : customizable_light_device = customizable_light_device{}
    
    # Defense turret that activates on security breach
    var DefenseTurret : automated_turret_device = automated_turret_device{}
    
    # Audio device for alarm sounds
    var AlarmSound : audio_player_device = audio_player_device{}
    
    # Security barrier for lockdown
    var SecurityBarrier : barrier_device = barrier_device{}
    
    # Time in seconds before system auto-resets
    @editable
    var AutoResetTime : float = 30.0

Part 3: Event Setup and System Activation

Now let's implement the core security system logic:

    # Initialize system when experience starts
    OnBegin<override>()<suspends>:void=
        # Subscribe to detection events
        if(Detector:perception_trigger_device):
            Detector.AgentLooksAtDeviceEvent.Subscribe(OnIntruderDetected)
    
    # Called when an intruder is detected
    OnIntruderDetected(Agent:agent):void=
        # Activate all security measures
        ActivateSecuritySystem()
        # Start auto-reset timer
        spawn{AutoResetSequence()}
    
    # Activates all security components
    ActivateSecuritySystem():void=
        if(AlarmLight:customizable_light_device):
            AlarmLight.TurnOn()
        
        if(AlarmSound:audio_player_device):
            AlarmSound.Play()
            
        if(DefenseTurret:automated_turret_device):
            DefenseTurret.Enable()
            
        if(SecurityBarrier:barrier_device):
            SecurityBarrier.Enable()

Part 4: Auto-Reset Implementation

Let's add the auto-reset functionality:

    # Handles the automatic reset sequence
    AutoResetSequence()<suspends>:void=
        # Wait for specified time
        Sleep(AutoResetTime)
        # Reset system
        DeactivateSecuritySystem()
    
    # Deactivates all security components
    DeactivateSecuritySystem():void=
        if(AlarmLight:customizable_light_device):
            AlarmLight.TurnOff()
        
        if(AlarmSound:audio_player_device):
            AlarmSound.Stop()
            
        if(DefenseTurret:automated_turret_device):
            DefenseTurret.Disable()
            
        if(SecurityBarrier:barrier_device):
            SecurityBarrier.Disable()

Setting Up in UEFN

  1. Create a new UEFN project or open an existing one
  2. Place the required devices in your scene:
    • Perception Trigger Device
    • Customizable Light Device
    • Automated Turret Device
    • Audio Player Device
    • Barrier Device
  3. Create a new Verse file and paste the complete code
  4. Assign your devices to the corresponding variables in the security system device
  5. Configure the AutoResetTime as needed

Testing Your Security System

  1. Enter Play mode
  2. Approach the perception trigger's detection area
  3. The system should activate:
    • Lights will turn on
    • Alarm will sound
    • Turret will activate
    • Barrier will enable
  4. After the specified AutoResetTime, the system will automatically deactivate

Customization Options

  • Adjust the AutoResetTime to control how long the system stays active
  • Configure the Perception Trigger's detection range and angle
  • Customize the alarm sound and light patterns
  • Position the barrier and turret for optimal coverage

This security system provides a foundation that you can build upon for your own creative experiences. Try adding additional features like:

  • Multiple detection zones
  • Different security levels
  • Player team exceptions
  • Custom reset conditions

Happy coding!

Complete Code

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

# Security system that manages detection and response
# Can be configured with various security devices and will automatically
# respond to intruders with configurable reset time
security_system_device := class(creative_device):
    # Detection device that acts as our motion sensor
    var Detector : perception_trigger_device = perception_trigger_device{}
    
    # Alarm light that activates when system is triggered
    var AlarmLight : customizable_light_device = customizable_light_device{}
    
    # Defense turret that activates on security breach
    var DefenseTurret : automated_turret_device = automated_turret_device{}
    
    # Audio device for alarm sounds
    var AlarmSound : audio_player_device = audio_player_device{}
    
    # Security barrier for lockdown
    var SecurityBarrier : barrier_device = barrier_device{}
    
    # Time in seconds before system auto-resets
    @editable
    var AutoResetTime : float = 30.0
    
    # Initialize system when experience starts
    OnBegin<override>()<suspends>:void=
        # Subscribe to detection events
        if(Detector:perception_trigger_device):
            Detector.AgentLooksAtDeviceEvent.Subscribe(OnIntruderDetected)
    
    # Called when an intruder is detected
    OnIntruderDetected(Agent:agent):void=
        # Activate all security measures
        ActivateSecuritySystem()
        # Start auto-reset timer
        spawn{AutoResetSequence()}
    
    # Activates all security components
    ActivateSecuritySystem():void=
        if(AlarmLight:customizable_light_device):
            AlarmLight.TurnOn()
        
        if(AlarmSound:audio_player_device):
            AlarmSound.Play()
            
        if(DefenseTurret:automated_turret_device):
            DefenseTurret.Enable()
            
        if(SecurityBarrier:barrier_device):
            SecurityBarrier.Enable()
    
    # Handles the automatic reset sequence
    AutoResetSequence()<suspends>:void=
        # Wait for specified time
        Sleep(AutoResetTime)
        # Reset system
        DeactivateSecuritySystem()
    
    # Deactivates all security components
    DeactivateSecuritySystem():void=
        if(AlarmLight:customizable_light_device):
            AlarmLight.TurnOff()
        
        if(AlarmSound:audio_player_device):
            AlarmSound.Stop()
            
        if(DefenseTurret:automated_turret_device):
            DefenseTurret.Disable()
            
        if(SecurityBarrier:barrier_device):
            SecurityBarrier.Disable()
BizaNator

BizaNator

Verified CreatorGame DeveloperContent Creator
Unreal EngineVerseGame Design3D Modeling