# 这个部分的代码有错误https://dev.epicgames.com/documentation/zh-cn/fortnite/lights-and-bridges-02-puzzle-component-in-fortnite#finalcodeforpuzzleverse

**URL:** <https://forums.unrealengine.com/t/https-dev-epicgames-com-documentation-zh-cn-fortnite-lights-and-bridges-02-puzzle-component-in-fortnite-finalcodeforpuzzleverse/2661720>\
**Category:** World Creation\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [October 2, 2025, 12:59pm UTC](https://forums.unrealengine.com/t/https-dev-epicgames-com-documentation-zh-cn-fortnite-lights-and-bridges-02-puzzle-component-in-fortnite-finalcodeforpuzzleverse/2661720 "2025-10-02T12:59:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![seechine](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@seechine](https://forums.unrealengine.com/u/seechine)\
**Post date:** [October 2, 2025, 12:59pm UTC](https://forums.unrealengine.com/t/https-dev-epicgames-com-documentation-zh-cn-fortnite-lights-and-bridges-02-puzzle-component-in-fortnite-finalcodeforpuzzleverse/2661720/1 "2025-10-02T12:59:04Z")

</div>

关于场景图的教程，在这一部分的链接中，有错误。不和官方能否修改一下？

using { /Verse.org/Simulation }  
using { /UnrealEngine.com/Temporary/Diagnostics }  
using { /Verse.org/SceneGraph }  
using { Logging }

puzzle\_solved\_event := class(scene\_event){}

# Scene Graph component handling puzzle component triggered events and when the puzzle is solved.

puzzle\_component := class\<final\_super\>(component):

```auto
# Is this puzzle component solved
var<private> Solved<public>:logic = false

# Map of puzzle pieces and whether they have been "solved"
var<private> TriggerableEntities<private>:[]entity = array{}

# Disable puzzle pieces triggering once puzzle is solved
@editable
DisablePuzzleTriggerablesWhenSolved<private>:logic = false

# Initialize array of triggerable entities
InitializeTriggereableDescendantEntities<private>()<transacts>:void=
    for:
        DescendantEntity : Entity.FindDescendantEntities(entity))
        DescendantEntityComponent : DescendantEntity.GetComponents()
        CastToTriggerable := triggerable[DescendantEntityComponent]
        CastToTriggerable.PuzzlePiece?
    do:
        set TriggerableEntities += array{DescendantEntity}

# Decides whether puzzle is solved
IsPuzzleSolved<private>()<decides><transacts>:void=
    for:
        TriggerableEntity : TriggerableEntities
        TriggerableEntityComponent : TriggerableEntity.GetComponents()
        CastToTriggerable := triggerable[TriggerableEntityComponent]
        CastToTriggerable.PuzzlePiece?
    do:
        CastToTriggerable.InSolvedState[]

# Clean up or subsequent events after puzzle is solved
HandlePuzzleSolved<private>():void=
    set Solved = true
    Log("Puzzle Solved!", LogPuzzleComponent, ?Level:=log_level.Normal)
    if (DisablePuzzleTriggerablesWhenSolved?):
        DisableTriggerableComponents()
    Log("Sending down solved event", LogPuzzleComponent, ?Level:=log_level.Normal)
    Entity.SendDown(puzzle_solved_event{})

# Async wrapper for determining whether puzzle is solved
CheckPuzzleSolved()<suspends>:void=
    Sleep(0.25)
    if (not Solved?, IsPuzzleSolved[]):
        HandlePuzzleSolved()

# Disable puzzle pieces
DisableTriggerableComponents<private>():void=
    for:
        DescendantEntity : Entity.FindDescendantEntities(entity)
        DescendantEntityComponent : DescendantEntity.GetComponents()
        CastToTriggerable := triggerable[DescendantEntityComponent]
        CastToTriggerable.PuzzlePiece?
        CastToEnableable := enableable[DescendantEntityComponent]
    do:
        CastToEnableable.Disable()

# Handle triggered events sent up from child entities
OnReceive<override>(SceneEvent:scene_event):logic=
    Log("Received scene event.", LogPuzzleComponent, ?Level:=log_level.Normal)
    if (TriggeredEvent := triggered_event[SceneEvent], TriggeredEntity := TriggeredEvent.TriggeredEntity?):
        spawn{CheckPuzzleSolved()}
        true
    false

# Runs when the component should start simulating in a running game.
OnBeginSimulation<override>():void =
    # Run OnBeginSimulation from the parent class before
    # running this component's OnBeginSimulation logic
    (super:)OnBeginSimulation()
    InitializeTriggereableDescendantEntities()

```
