Open mcclure opened 6 years ago
Also, aside from the bug-- I am sorry, I am very confused, but I do not understand why the extension-helloworld.js script is running. It is not attached as a ScriptComponent to anything in the scene (I am using this sample project https://github.com/ConquestArrow/UnrealTSTemplate but there are also similar extension- files in the sample project for the https://github.com/ncsoft/Unreal.js repo). Can you explain, why does extension-helloworld.js run? Does UnrealJS just run any js file beginning with extension- in case it is an editor extension?
Yes. When the JavascriptEditor Module starts, The script will be executed. https://github.com/ncsoft/Unreal.js-core/blob/master/Content/Scripts/editor.js
Short description: If an error or exception throw occurs in the cleanup function returned by a script component, hot reloading will no longer work and the same error will be printed on every single script reload even if it is fixed in the code.
Demonstration: I am running Unreal 4.18.0 with the current UnrealJS from the Marketplace. I have a project with the following script as "extension-helloworld.js":
I try the following:
I add another exclamation point to "hello, world!!"
Result: I see "hello, world!!!" in the Javascript Console. This is expected.
Inside the
// cleanup
function before the "return", I placethrow new Exception()
Result: I see "hello, world!!!" in the Javascript Console. This is expected.
I add another exclamation point to "hello, world!!!".
Result: I see in the Javascript console:
This also is expected. The cleanup function from step 2 is running and it a "throw".
I remove the
throw new Exception()
from the// cleanup
function.Result: I see in the Javascript console:
This is expected because there is a "throw" in the cleanup function from step 3, which runs when it loads my new corrected script.
I add one more exclamation point to "hello, world!!!!".
Result: I see in the Javascript console:
This is not expected. The "exception!" code is not in the cleanup function from step 4. It appears that if there is an error during cleanup, the cleanup function is removed from the list of cleanup functions to run. From this point on I cannot get my code to function except by closing and reopening Unreal.
Expected behavior:
It is very difficult when this bug starts occurring to understand what is wrong, as the same error keeps getting printed over and over even though the code containing the error has been fixed. I would like to recommend two things:
(1) When an exception is thrown/an error occurs during a cleanup function, print a message clearly stating "Error during cleanup:". This way, the message in the javascript console will be easier to understand.
(2) If an error occurs during a cleanup function, remove the cleanup function from the list of cleanup functions to run, so that hot-loading can continue to occur and the user will not have to close Unreal.