getnamo / NodeJs-Unreal

Embed node.js as an Unreal Engine plugin.
MIT License
239 stars 34 forks source link

Node.Emit doesn't work in fresh loaded Level. #39

Closed WailedParsley36 closed 1 year ago

WailedParsley36 commented 2 years ago

I just ran into this problem and need help! I tried to modify the code, but with no effect. I was focusing on it over 8 hours and with still same result. On the first play, everything works fine, but after the first play it doesn't call the "OnScriptInit" function (Code below). If I restart Unreal it is the same as before. First play good and then bad. If I get a breakpoint in the function it starts working for every play, but the breakpoint must be there (I don't want that). I tried putting a delay and waiting 3 seconds for the node to initialize, but that didn't change anything.

I have a game mode in which I have this Node component: image

Then in event "Component activated" I'm trying to bind events that are called in the firebase.js script.

Event graph: image

Firebase.js: image

Bind events func: image

OnScriptInit function (this doesn't get called by the ipc.emit() in the script as mentioned above): image

InitializeFirebase func: image

BP_PCreatorInstance travel function that register the refresh bool (this works fine): image

FIRST play after traveling to another level and refreshing: image

BAD play after traveling to another level and refreshing: image

getnamo commented 2 years ago

At a glance, traveling could de-link your node cmd link (see: https://github.com/getnamo/nodejs-ue4/blob/master/Source/NodeJs/Public/NodeComponent.h#L178 is an owned pointer on cmd, and each component generates a new cmd https://github.com/getnamo/nodejs-ue4/blob/master/Source/NodeJs/Private/NodeComponent.cpp#L30). Likely some refactor is needed to ensure node cmd link stays valid between traveling (e.g. link re-use via tag or something like it, or use static allocation like socket.io does).

This is a rough experimental plugin and I currently don't have any spare OS time to attend its fixes apart from pointing where they could be; someone else will need to peek and contribute fixes for stability.

JonesHong commented 1 year ago

Hi, I had try something similar. Change level by cheat mode. Even though I load same map. NodeJs won't work!

But if I destroy NodeJs Actor and wait for 5s to chang level. It works for me successfully. I guess socket thread can't be restart by itself. My project test vedio link

  1. Get weather data. (OK)
  2. Nothing
  3. Get weather data. (OK)

Add destroy and wait for 5s.

  1. Get weather data. (OK)
  2. Get weather data. (OK)
  3. Get weather data. (OK)

Note. Delay time lower 5s may be crashed.