How to Use,(version 2) - npcbx/AsyncFuncCaller GitHub Wiki

version 1 is for ue4.18

version 2 is for ue4.23 4.26

Prepare

1.download plugin and enable it 2.create a new level, drag AsyncBPFuncTest_BP actor into it. 3. begin play, press num1 num3 num4 num5 to see result.

method 1, start async bp function by function name.

metho1-1 metho1-2

  1. use startAsyncFuncByFuncName (in 4.18 is StartAsyncFunc ) node To exec bp function in new thread,fill in A Func Name.
  2. Create The Same Name Func.

method 2, start async bp function by option.

metho2-1

  1. Create 3 Custom Event(marked as Event1,2,3) And An Empty Obj Array to make A option

  2. Use Option to involve StartAsyncFuncWithOption to start AsyncEvent, Store Result As AsyncFuncWorker.

  3. Event1 will be running on NewThread, Event2 will be running on GameThread ,Can be involved in Event1 by ExeCuteGameThreadOnGameTHread with AsyncFuncWorker. Event3 Will be running on GameThread, Auto be Involved When First Event Is Over,

  4. make sure not Use EndPlay Before event1 over.

  5. Event2,3 Can be empty.

method 3, start loop Event.

metho3-1 metho3-2 metho3-3

  1. Use CraeteAAsyncLoopEventManager to Create A LoopEventManager And Store It. Create 4 Custom Event(marked as Event1,2,3, 4) And An Obj Array to make A option .
  2. Use LoopEventManager And Created Option To StartAsyncLoopEvent .Store Result As Runnable Thread Worker
  3. event2 will be running in Loop in New Thread, Event3 will be running on GameThread ,Can be involved in Event1 by ExeCuteGameThreadEvent with RunnableThreadWorker. Event4 Will be running on GameThread, Auto be Involved When loop end,
  4. Use RunnableThreadWorker to Call EndTread, PauseThread and ResumeThread.
  5. Event1 will be running on NewThread .Use RunnableThreadWorker to Call ExecuteCriticalEvent In event1. CriticalEvent means if more than one threads is created by same LoopEventManager, they Can not do Critical Event concurrently.
  6. I Suggest Use MakeCurrentThreadSleep for 0.02 second after one loop.
  7. Call End Thread by Runnable Thread workder ANd Release LoopEventManager In EndPlay
  8. There I ceated a Calculator(PrimeNumCalculator) and a Widget(TestThread_Wdb) For Test.

Notice

  1. Objs Array is The Array in option in Step 1, Use it to Send Objs to New Thread, Because Some bp Function Can only be Run In GameThread, such As GetAllActors.
  2. Use lib Function GetNowThreadId TO Get What THread Current Node is In , use MakeCurrentThreadSleep instead of delay to stop Thread for a while.