Scene Graph: Can you subscribe to Fortnite Devices?

I’m trying my hand at Scene Graph in Experimental mode and I am trying to spawn an Entity at the location of an eliminated player. I have a prefab for my object spawner component with this component in my Scene and it’s connected to my Elimination Manager there via this:
@editable ElimManager : elimination_manager_device = elimination_manager_device{}

In my OnSimulate function I have:
ElimManager.EliminationEvent.Subscribe(SpawnWhereSomeoneDied)

And that runs this function:

SpawnWhereSomeoneDied(Agent: agent): void =
        Print("Running SpawnWhereSomeoneDied function")
        # Let's spawn something where a player is elimination
        
            if:
                SimulationEntity:=Entity.GetSimulationEntity[]
                FC:=Agent.GetFortCharacter[]
            then:
                PlayerT:=FromTransform(FC.GetTransform())
                SL:=PlayerT.Translation
                SpawnTransform:=(/Verse.org/SpatialMath:)transform{Translation:=SL}

                #Create an instance of the object
                MyInstance: Prefabs.Prefab_E_MyPrefab = Prefabs.Prefab_E_MyPrefab {}

                # Add the prefab isntance to the scene.
                SimulationEntity.AddEntities(array{MyInstance})
                # Set the spawn location of the prefab to the SpawnLocation variable
                if:
                    TransformComponent := MyInstance.GetComponent[transform_component]
                then:
                    # change spawn location to SpawnLocation
   TransformComponent.SetGlobalTransform((/Verse.org/SpatialMath:)transform{Translation:=SL})

Now in theory this should work, but the function just never fires off it seems.
I have a similar Verse-device setup connected to the Elimination Manager for prop-spawning in the same island, and that is working. Am I doing something wrong, or does subscribing to

I think I read in a forum post that elimination manager is inconsistent, could you try replacing it with a team settings device and subscribe for teammember eliminated event, and see if that fires correctly?

Yeah, that might be an issue, but a Trigger device should not be unreliable, so when both don’t work it sounds to me like there might be an issue with components subscribing to verse devices somewhere (or I’m doing it wrong?).

Anyway, Scene Graph is delayed until Q2, so I’m putting this function on pause for now. Guessing this will be fixed or documented better later.

I’m seeing something similar with an @editable playerplayer_spawner_device inside of a custom component. I subscribe with something like Spawner.SpawnedEvent.Subscribe(SpawnPlayer) in OnSimulate, but SpawnPlayer is never called (when it 100% should be). I’ve verified OnSimulate is correctly called as well as the subscribe function.

1 Like

Do you have a copy paste of the code? Just to check and to try for myself and possibly take videos/write a bug report if it doesn’t work for me either.

1 Like

Not a straight copy/paste of my code since I removed some of my game logic, but these are the parts that matter. You should be able to copy/paste it still.

All you need to do is:

  1. Create a new entity in the game
  2. Attach the test spawner component
  3. Add some player spawners and attach to the editable on the entity component

I tried explicitly making the SpawnPlayer public because I thought maybe there was a weird scoping issue, but that didn’t fix it. I also made a completely separate class outside of the component and subscribed to a method in that new class, but it also didn’t work.

Making a device, using the same spawners, and subscribing worked. There’s just something weird about the components.

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

# A Verse-authored component that can be added to entities
test_spawner_component<public> := class<final_super>(component):

    @editable
    PlayerSpawners : []player_spawner_device = array{}
  
    # Runs when the component should start simulating in a running game.
    OnSimulate<override>()<suspends>:void =
        Print("This print statement will work")

        for (Spawner : PlayerSpawners):
            Spawner.SpawnedEvent.Subscribe(SpawnPlayer)

    SpawnPlayer(InAgent : agent) : void=
        Print("This text will never print")

OnSimulate runs before devices. You can use a verse device to spawn an entity with the component. You can even pass through a device reference using a functiion on the component, or you can have the component looks for devices with X tag. X being whatever you name you want of course. Don’t forget to add the tag to the device in question if you go that route.

2 Likes

Oh yeah, that makes a lot of sense why the subscribe isn’t working then. Thank you!

1 Like