Crash: two verse scripts ref each other

Please select what you are reporting on:

UEFN

What Type of Bug are you experiencing?

Crash

Summary

When two verse scripts ref each other, causes UEFN to crash.

Steps to Reproduce

Create 2 scripts that ref each other. Example:

test_manager.verse
@editable
TestSystem : test_system = test_system{}


test_system.verse
@edtiable
TestManager : test_manager = test_manager{}

Save and try to build verse code. This will crash uefn.

Expected Result

It should produce an error instead. I assume it crashes because verse wants to be opinionated and doesn’t allow scripts that cross-reference each other.

Observed Result

It crashes uefn and can’t open the project until you comment out one of the references.

Platform(s)

PC

This bug is reported already and will be fixed in a future version I believe, you can look into this post if you want to Also a Workaround is for you to instead of having an editable of the device itself to have a creative_device and then inside the script to use it do

if(RealTestManager:=test_manager[TestManager]):
     RealTestManager.MyFunctionHere()

You can do that ^ to avoid referencing the device directly till the bug is fixed. Hope you ahve a good evening.

Change your editables to optional types:

game_manager:=class(creative_device):
  @editable
  MaybeTestSystem : ?test_system = false

  OnBegin<override>():void=
      if(TestSystem:=MaybeTestSystem?):
            TestSystem.SomeFunction()
   
  GetTestSystem()<decides><transacts>:test_system= # <- External class access
      MaybeTestSystem?

another_class:=class:
     GameManager:game_manager
     
     SomeFunction2():void=
           if(TestSystem:=GameManager.GetTestSystem[]):
                  TestSystem.SomeFunction()
2 Likes

This technically isn’t a bug, it’s just a quirk of the language currently. When you create two verse devices that reference each other, it creates a circular dependency which is not allowed and will cause crashes.

The reason for this is when you write @editable TestSystem:test_system = test_system{} what you are actually doing is creating an instance of test_system and saving it to the TestSystem member. The problem is test_system requires an instance of test_manager and so it creates it and saves it to the TestManager member. But now the test_manager requires an instance of test_system and so on and so on… This will loop forever and is the reason for the crash.

Personally if I ever need two devices to have saved references for each other I will use optionals.

test_manager.verse
@editable
var TestSystemOP : ?test_system = false
test_system.verse
@editable
var TestManagerOP : ?test_manager = false

Optionals avoid this issue entirely and can still be set like any other editable member, but do need to be queried to get the value you want. You can get and set the value of optionals as shown below.

GetTestSystem():test_system=
    if (TestSystem:= TestSystemOP?):
        return TestSystem
    else:
        Print("Test System does not exist)

SetTestSystem(TestSystem:test_system):void=
    set TestSystemOP = option {TestSystem}

More info can be found in the docs: Option | Unreal Editor for Fortnite Documentation | Epic Developer Community

1 Like