Is there a way to detect if 2 players collide?

Is this possible? Even with some scene graph hack where I attach a mesh to each player?

Hey @RandomFoghorn how are you?

There is no way to detect collisions in UEFN but you can use thise workaround to solve almost any case you need.

To do it, you need to calculate the distance between players in loop every certain amount of time, and then execute your code if two players are within the desired radius.

Let me show you the code:

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }

# Device responsible for detecting proximity between players using distance checks
player_proximity_detector := class(creative_device):

    # Time (in seconds) between each proximity check
    # Smaller values = more responsive but more expensive
    @editable
    CheckInterval : float = 0.2

    # Radius used to consider two players "colliding" (in Unreal units)
    @editable
    ProximityRadius : float = 150.0

    # Called once when the device starts
    # Starts the continuous proximity detection loop
    OnBegin<override>()<suspends>:void =
        StartDetectionLoop()

    # Main loop that periodically checks distances between all players
    # Uses Sleep to avoid running every frame
    StartDetectionLoop()<suspends>:void =
        loop:
            CheckAllPlayerDistances()
            Sleep(CheckInterval)

    # Iterates through all players in the playspace
    # Compares every unique pair of players exactly once
    CheckAllPlayerDistances():void =
        Players := GetPlayspace().GetPlayers()

        # First loop: pick Player A
        for (IndexA := 0..Players.Length - 1):
            # Safety check to ensure the player reference is valid
            if(PlayerA := Players[IndexA]):
                # Ensure Player A has a spawned fort_character
                if(CharacterA := PlayerA.GetFortCharacter[]):
                    # Second loop starts at IndexA + 1 to avoid duplicate pairs
                    # and prevent Player A vs Player A checks
                    for (IndexB := IndexA + 1..Players.Length - 1):
                        if(PlayerB := Players[IndexB]):
                            # Ensure Player B has a spawned fort_character
                            if(CharacterB := PlayerB.GetFortCharacter[]):
                                # Check if both players are within the defined radius
                                CanHandle := ArePlayersWithinRadius(CharacterA, CharacterB, ProximityRadius)

                                # Only handle the pair if they are close enough
                                if(CanHandle = true):
                                    HandlePlayersInRange(PlayerA, PlayerB)

    # Computes whether two fort_characters are within a given distance
    # Returns a logic value instead of a float comparison
    ArePlayersWithinRadius(CharA:fort_character, CharB:fort_character, Radius:float ) : logic =
        # World positions of both characters
        PosA := CharA.GetTransform().Translation
        PosB := CharB.GetTransform().Translation

        # Distance-based proximity check
        if (Distance(PosA, PosB) <= Radius):
            true
        else:
            false

    # Called when two players are detected within the proximity radius
    # This is where gameplay logic should be implemented
    HandlePlayersInRange( PlayerA:player, PlayerB:player ) : void =
        Print("Players are colliding")

As you can see, with this device you can change the check interval (it should be ALWAYS more than 0.0), and the proximity radius. With those values you you be able to know if two players are too close, and then trigger whatever you want to do with them!

Remember you can change the proximity radius to make it feel more like a collission than an overlap, and vice versa!

Hope this helps you! Le me know if you need more info!