Unreal 4 Threading - Running a Task on a Worker Thread

Sdílet
Vložit
  • čas přidán 21. 08. 2024
  • In this tutorial we will use C++ with Unreal Engine 4 to get a backbround task running via the thread pool system.

Komentáře • 44

  • @jaybabcock9123
    @jaybabcock9123 Před rokem +1

    Man I spent like 7 hours straight trying to figure this out on my own. Should have just sat through this video when I first opened it.

  • @alessandroameni
    @alessandroameni Před 5 lety +5

    You really saved my life with this video! I'll be grateful to you forever! ;-)

  • @jonlangford5224
    @jonlangford5224 Před 6 lety +3

    Thank you for the tutorial! Really informative and easy to understand

  • @Melandowski
    @Melandowski Před 4 lety +1

    Muchisimas gracias por la informacion, mi problema no solo era hacer cosas en segundo plano si no leer datos (de XML) y pasarselos al hilo principal una vez terminada la ejecucion para básicamente hacer una pantalla de carga con todas las de la ley. Gracias a tu video y a 2 o 3 cosas más he podido implementarlo. Saludos!

  • @AliziaKaline
    @AliziaKaline Před rokem

    Thank for the video. I don't know if it was intentional to increase the number of calculations, but to test prime or not, you can just store previous primes and test them only, no need to test all integer until x/2 ;)

  • @whiteowleducation
    @whiteowleducation Před 2 lety

    Good video. Thanks for putting this together.

  • @ivansologubov5631
    @ivansologubov5631 Před 5 lety

    Yes, a great tutorial. Thanks for creating it!

  • @brianlaflamme1948
    @brianlaflamme1948 Před 4 lety

    Good stuff! thanks for the knowledge! I definitely need this for my Ai Pathfinding Spline system.

  • @MrZadocH
    @MrZadocH Před 5 lety

    good i was learning how to implement but your example is the best i found thanks for it

  • @Blueshark905
    @Blueshark905 Před 6 lety +1

    This was very interesting. Thank you for sharing your knowledge friend :)

  • @angrybonobro8711
    @angrybonobro8711 Před 3 lety

    Very helpful! Thank you very much

  • @hongwangg
    @hongwangg Před 4 lety +1

    Is it possible to check whether the task is finished in the main thread? Since I need to retrive the calculated data from the task and call another function

  • @ZangJM
    @ZangJM Před 5 lety +6

    what if a want to fire a event on the blueprint when the background task finish?

    • @VladyVeselinov
      @VladyVeselinov Před 3 lety

      you can use delegates for that forums.unrealengine.com/community/community-content-tools-and-tutorials/13915-tutorial-creating-and-using-delegates-c-and-accessing-them-in-blueprints

  • @pwndulquiorra
    @pwndulquiorra Před 4 lety +9

    Okay, so this tutorial is pretty good but, for the purposes of optimization in my own game, I want to know the method for building the worker thread to work to work on long running or perpetual tasks. And since this tutorial specifically states to not do that with this one, I was wondering how to program a worker thread that could do just that.
    Thank you and have a good day.

    • @claysutton6597
      @claysutton6597 Před 3 lety

      Sorry to be so off topic but does anybody know of a trick to log back into an instagram account..?
      I stupidly forgot the account password. I appreciate any tricks you can offer me

    • @bobbybrantley8298
      @bobbybrantley8298 Před 3 lety

      @Clay Sutton instablaster :)

    • @claysutton6597
      @claysutton6597 Před 3 lety

      @Bobby Brantley Thanks for your reply. I got to the site on google and Im trying it out now.
      I see it takes a while so I will reply here later with my results.

    • @claysutton6597
      @claysutton6597 Před 3 lety

      @Bobby Brantley It did the trick and I finally got access to my account again. Im so happy!
      Thanks so much you really help me out :D

    • @bobbybrantley8298
      @bobbybrantley8298 Před 3 lety

      @Clay Sutton happy to help :D

  • @ZangJM
    @ZangJM Před 5 lety

    Thank you very helpfull tutorial!

  • @calmsh0t
    @calmsh0t Před 5 lety +2

    Can I let the task return a value?

  • @CyberWolf755
    @CyberWolf755 Před 6 lety

    Superb tutorial!
    Could you go provide us with the classes that you made and if there is some good documentation for beginners for threading?

    • @gamedevsocietybu6179
      @gamedevsocietybu6179  Před 6 lety

      If I can find the UE4 project then I'll zip it up and link it for you. I think it will be on my work PC though so I cannot check right now.

  • @LudwigvanBeethoven2
    @LudwigvanBeethoven2 Před 4 lety

    How can I make callbacks for the caller thread?
    I managed to do it with
    AsyncTask(ENamedThreads::GameThread, [OnReportProgress = OnReportProgress ]() { OnReportProgress.ExecuteIfBound(....) })
    this works. but sometimes I want to cancel the running work and run a new work with new parameters. when I cancel the thread, things go wrong and i get access violation errors.

  • @usernotfound.3837
    @usernotfound.3837 Před 3 lety

    what a fucking legend you are

  • @isaackershnerART
    @isaackershnerART Před 2 lety

    Thank you! im fairly new to c++ but how would i go about outputing the parameters through the blueprint function? say pass the prime values found into an array in BP...

  • @MarkusRomulusMaximus
    @MarkusRomulusMaximus Před 5 lety

    Hey there, nice tutorial! Any idea why TStatID throws identifier undefined? I updated the includes for IWYU standard for UE 4.22 with #include "Runtime/Core/Public/Stats/Stats.h", but I am not having any luck there.

    • @weekendum7880
      @weekendum7880 Před 5 lety

      Just in case you haven't figured it out yet, it's because it's not "D" but "d"

    • @MarkusRomulusMaximus
      @MarkusRomulusMaximus Před 5 lety

      @@weekendum7880 Mother of god! Thanks you so much!

  • @umeshramchandani9033
    @umeshramchandani9033 Před 6 lety

    Thanks and this was really helpful !!! I would love a tutorial on the niagara system also I crashed into a problem where I need a 2d array for textures in material. Are there any ways to add it ourselves ?

    • @gamedevsocietybu6179
      @gamedevsocietybu6179  Před 6 lety

      I will hopefully be making more tutorials soon, and can cover Niagara then.
      I don't think you can make 2D arrays. You might be able to have an array of a struct which itself contains an array, or have a normal array then you "step" over as though it was 2D.

    • @umeshramchandani9033
      @umeshramchandani9033 Před 6 lety

      @@gamedevsocietybu6179 there is a mention of it in the documentation but I have no idea how to use it so I think I need to put everything in one image and access from it :(

  • @calmsh0t
    @calmsh0t Před 5 lety

    What do I need to do to use FNonAbondableTask? using it throws a compile error "undefined class"

  • @dipamphoenix760
    @dipamphoenix760 Před 5 lety

    Can you show how to do SaveGame Asynchronously, I mean saving the game in background and gameplay will continues at the same time

    • @gamedevsocietybu6179
      @gamedevsocietybu6179  Před 5 lety

      I haven't tried it, but can you call the CreateSaveGame and SaveGameToSlot functions in UGameplayStatics (I think) from the background thread DoWork function?

  • @Nighta90
    @Nighta90 Před 6 lety

    why do primesearchtask have to have int32 as an output?

    • @gamedevsocietybu6179
      @gamedevsocietybu6179  Před 6 lety +1

      Not sure which int32 you mean by "output", do you mean the int32 that gets passed to the constructor?
      That is just there so we can pass a number to our class telling it how many prime numbers to find, otherwise it could just run forever. If you mean why is it "int32" rather than just "int" that is because the engine likes you to specify what type of int you mean, normal "int" do not show up in Blueprint but "int32" do.

  • @Metalwrath2
    @Metalwrath2 Před 4 lety

    you are not using UE4 naming convention...