Platforms that appear and disappear periodically are a staple for platforming game modes like obstacle courses. They require players to time their jumps to make it to the next platform. If they miss, they’ll fall and have to start over.
This example shows how to create a disappearing platform using Scene Graph and a Verse-authored component. Compare this to the Verse-authored device implementation of the same concept in Disappearing Platform on Loop.
Making Platforms Disappear
Follow these steps to create a disappearing platform using Scene Graph:
Add an entity to your scene named DisappearingPlatform. See Working with Entities and Components to learn more about adding entities and components to your scene.
Add the mesh_component to your disappearing platform entity, and set the mesh to cube.
Create a new Verse component named
disappear_on_loop_component, add the component to your disappearing platform entity and save the entity. To learn how to create your own component, see Creating Your Own Component Using Verse.Open your
disappear_on_loop_componentin VS Code to edit it in the following steps.Add an editable
floatproperty to the component namedDuration. This determines how long the platform should be shown before it’s hidden, and how long it’s hidden before it appears again.Verseusing { /Verse.org } using { /Verse.org/Native } using { /Verse.org/Simulation } using { /Verse.org/SceneGraph } # Loops between hiding and showing the entity by enabling and disabling # its static mesh and collision components. disappear_on_loop_component := class(component):To hide a platform, you can make its static mesh invisible by turning off collision so a player can’t land on the platform. Add a new function that extends from
entitynamedHide()to yourdisappear_on_loop_componentclass, Inside this function, callGetComponents[]with the type you’re looking for, in this casemesh_component, returning the entity's static mesh. Then callDisable()on the static mesh.Verse# If the entity has a mesh or collision component, disable them. (Entity:entity).Hide():void= if: StaticMesh := Entity.GetComponent[mesh_component] then: StaticMesh.Disable()Add another
entityextension function namedShow()to yourdisappear_on_loop_componentclass. The implementation is the same asHide()but you’ll callEnable()instead on the static mesh components.Verse# If the entity has a mesh or collision component, enable them. (Entity:entity).Show():void= if: StaticMesh := Entity.GetComponent[mesh_component] then: StaticMesh.Enable()Finally in
OnSimulate(), use aloopexpression to loop hiding and showing the platform , callingSleep()each time. Your completedisappear_on_loop_componentclass should look like the following:.Verseusing { /Verse.org } using { /Verse.org/Native } using { /Verse.org/Simulation } using { /Verse.org/SceneGraph } # Loops between hiding and showing the entity by enabling and disabling # its static mesh and collision components. disappear_on_loop_component := class<final_super>(component):Save and compile your code.
In the UEFN Outliner, promote your DisappearingPlatform entity to a prefab named disappearing_platform_prefab. As a prefab, you can create more instances of your disappearing platform and update the look and base implementation for them all if you need to later. For how to promote entities to a prefab, see Prefabs and Prefab Instances.
Complete Script
Here is the complete code used in this section:
disappear_on_loop_component.verse
using { /Verse.org }
using { /Verse.org/Native }
using { /Verse.org/Simulation }
using { /Verse.org/SceneGraph }
# Loops between hiding and showing the entity by enabling and disabling
# its static mesh and collision components.
disappear_on_loop_component := class<final_super>(component):