ncsoft / Unreal.js

Unreal.js: Javascript runtime built for UnrealEngine
Other
3.67k stars 351 forks source link

runtime eval/compile #46

Closed getnamo closed 8 years ago

getnamo commented 8 years ago

So tried this out the other day, really awesome work!

Live reload works in the editor, but if you run standalone/packaged it won't which makes sense. My question is if there is a function or method you can call to reload and re-evaluate a javascript file in standalone/packaged games?

nakosung commented 8 years ago

devrequire.js requires directory watcher but it is excluded with non-editor release. It does just monitor file-change and call cleanup function what you returned, purge_modules() to invalidate js cache, and gc() to flush, then it require(your-js) to load.

So basically you should have a method to watch a file change outside editor to monitor file change. If you have one, and then just call purge_modules(); gc(); require('your-js')

:)

mflux commented 7 years ago

Any advice on getting a method to watch a file? I'm using grunt.

Currently I have a ghetto:

function main() {

  purge_modules(); gc();

  setTimeout( function(){

    //  my game code using require()

  }, 500 );

  //  return a cleaup function
  if( GWorld.IsServer() ) {
    return function(){
      cleanupGameplayActors();
    };
  }
  else{
    return function cleanup(){};
  }
}
getnamo commented 7 years ago

I've usually used windows specific functions to watch for folder changes, but ue4 has platform agnostic file functions https://wiki.unrealengine.com/File_Management,_Create_Folders,_Delete_Files,_and_More which should be more appropriate. Exposing any of those c++ methods, e.g. file timestamp, to unreal.js and running a polling thread or receiving a system callback should get you what you're looking for. Maybe nako has exposed some of these utilities in ujs already?