Custom Item Spawner - ItemDefinition??

Hello! I have a couple of questions :slight_smile:

  1. I wanted to create a custom item spawner, but I can’t seem to find out how to make an editable array of ItemDefinition similar to how the Item Spawner device from Epic looks to work. Is this even possible?
  2. I’ve read recently that it’s not possible to spawn a device, but a workaround is to nest a Creative Device in a blueprint and spawn the blueprint. BUT, you can’t use this hack with a custom device. Is this true?

Thanks!

You can spawn custom items using Verse code - I’ve put an example below. If you put that in a Verse file, and build Verse code, it will create a device which you can drag into the level. The device has a property on it (the @editable field) which is the item to spawn. The item will spawn in the same location as the device.

Bear in mind that items in Verse will have a different name than the WID i.e. fort_item_auto_shotgun_uncommon rather than WID_Shotgun_CoreDPS_Athena_UC.

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

simple_item_spawner_device := class(creative_device) :

    @editable:
    ItemToSpawn:?subtype(entity) = false

    var SpawnedItem:?entity = false

    OnBegin<override>()<suspends>:void=
        if:
            entity_class:concrete_subtype(entity) := ItemToSpawn?
            NewItem := entity_class{}
            SimEntity := GetSimulationEntity[]
        then:
            # Create a transform from the device Translation and Rotation, but use the Scale from the Entity. 
            SpawnTransform := (/Verse.org/SpatialMath:)transform
                {
                    Translation := FromTransform(Self.GetTransform()).Translation,
                    Rotation := FromTransform(Self.GetTransform()).Rotation,
                    Scale := NewItem.GetGlobalTransform().Scale
                }

            # Set the NewItem to the location of the device. 
            NewItem.SetGlobalTransform(SpawnTransform)

            # Add the NewItem to the Simulation Entity. 
            SimEntity.AddEntities(array{NewItem})
            
            # Cache the Item so it can be removed on session end. 
            set SpawnedItem = option{NewItem}

    # OnEnd we have to cleanup any spawned entities.
    OnEnd<override>():void=
        if(ItemToRemove := SpawnedItem?):
            ItemToRemove.RemoveFromParent()

Thank you for sharing your code. I don’t see the link between the entity and the custom item, and where exactly to integrate it in the code? Can we directly reference the custom item without going through the entity?