State Tree Complete Introduction Course - BEGINNER FRIENDLY -

Sdílet
Vložit
  • čas přidán 24. 07. 2024
  • Yo What Is Good DEV GODS!
    In this long and in depth video I am going to show you how to use Unreal's future system for AI programming called State Trees. We will be implementing a simple Patrol, React & Attack AI behavior using a modular set up of state trees. I will cover some how's and why's and briefly talk about how to take this introduction and turn it into a more advanced system. If you are working on AI in you games and behavior trees seem daunting then this video is for you.
    Any off topic questions please ask them in my discord's forum channel.
    / discord
    0:00 - Title Graphic
    0:07 - Final Product Demo
    5:18 - State Tree Quick Start Guide
    26:55 - Set Up For Custom State Trees
    35:44 - Random Patrol Points
    49:46 - Orderly Patrol Points
    1:00:06 - React State Intro
    1:03:23 - React State Implementation
    1:21:04 - Ranged Attack State Intro
    1:24:37 - Ranged Attack State Implementation
    1:34:49 - Melee Attack State Challenge Solution
    Make sure to follow my other socials! Especially My KICK!
    linktr.ee/cain.godtier
    If you are watching this on FACEBOOK or INSTAGRAM come over to my youtube channel! I can't see the comments there.
    / @devgods
    Support me on patreon
    / devgods
    Subscribe to my youtube channel!
    / @devgods

Komentáře • 46

  • @DevGods
    @DevGods  Před 5 dny

    I recently added these files to github if anyone wants to check their code against mine when having issues.
    github.com/godtier-games/StateTreeCourseFiles

  • @thelionszen3352
    @thelionszen3352 Před 6 měsíci +2

    Thank you! I'll keep supporting your channel

  • @angeloadams8822
    @angeloadams8822 Před 6 měsíci +3

    Thank u for this

  • @in-HUMAN69
    @in-HUMAN69 Před 13 dny +1

    I really see a god😭😭🔥

  • @KittehBit
    @KittehBit Před 4 měsíci +3

    Nice video! :)
    A bit fast at times for a beginner, but I honestly prefer that to "too slow" vídeos, and I can rewind. :D
    The | symbol is a "pipe" btw. :)

  • @whyareless
    @whyareless Před 6 měsíci +1

    Nice video bro, cheers :)

  • @Al-Misanthropic-Bundy
    @Al-Misanthropic-Bundy Před 3 měsíci +2

    Hello! New viewer here. Thank you for the tutorial.

    • @DevGods
      @DevGods  Před 3 měsíci +1

      No problem! I hope it helps you better understand state trees! Good luck with your project!

  • @RigelOrionBeta
    @RigelOrionBeta Před 2 měsíci +1

    Amazing

  • @PaulGeraskin
    @PaulGeraskin Před 2 měsíci +1

    Thank you so much! Is it fine to use the State Tree for MainCharacter's states? For a simple single player game.

    • @DevGods
      @DevGods  Před 2 měsíci +1

      I don’t see why not

  • @xSp33dy97
    @xSp33dy97 Před 4 měsíci +1

    Thanks for the video. Can you make a tutorial on how to use/create evaluators, tasks and conditions in c++?

    • @DevGods
      @DevGods  Před 4 měsíci

      Just look at the source code of other tasks. It’s essentially copy pasta from there

    • @xSp33dy97
      @xSp33dy97 Před 4 měsíci +1

      @@DevGods Can't find how to access the parameters from StateTree

    • @DevGods
      @DevGods  Před 4 měsíci

      Like passing a value into your custom task from the state tree object? Or to fetch a value from your custom task inside the state tree

    • @DevGods
      @DevGods  Před 4 měsíci +1

      There’s a good example of both in UStateTreeTask_FindSlotEntranceLocation. Take a look at the structure they use as instance data and the categories each one of the Uproperties are in

  • @danilomontero7935
    @danilomontero7935 Před 13 dny +1

    Hello, I have a problem in case someone has suffered it too. When I believe the actor variable or AI Controller in a task, and I name it in its category as a context; I do not manage to access the variables or functions of this actor from this task; I try the basic, binding to its context within the State Tree, but nothing happens. I am using a tree ai component, does anyone know how they could link the context to the variables admitted? The strange thing is that by printing the name of this reference it does it correctly, but I still do not access its variables, functions, events, etc. Great video, you explain it very clearly

    • @DevGods
      @DevGods  Před 12 dny +1

      Are you setting the actors type explicitly in the context actor variable? For example of the graph runs only on BPYourCustomActor are you plugging in just the actor or your custom one? If it’s the latter you should have access to all of its blueprint variables and public getter functions

    • @danilomontero7935
      @danilomontero7935 Před 10 dny +1

      @@DevGods Thanks dude, I was trying to access personalized events from my context actor, within a Tree Task state; But my mistake was to think that the link was automatic, everything was solved with a cast to my NPC

  • @AetherMomon
    @AetherMomon Před 5 dny +1

    Great video, this has been really helpful to me! I have a question about State Tree that I can't seem to find any resources for online. How do you create a custom type of state for the State Tree plugin? I need to create a new custom type of state with customized functionality that is selectable in the State Tree UI. I also would like to know how to create custom transition type.

    • @DevGods
      @DevGods  Před 5 dny +1

      Like a state preset? That’s more advanced than this topic here since it requires adding code to the plugin’s editor and runtime module. You essentially need to add an editor action that is added to the state tree editor that will spawn your custom state class into the tree like it does for the other states. Transitions are a bit easier but I don’t think they can be made in blueprints. Pretty much you will have to rewrite some things in the plugin, as far as I know none of the really core things can be overridden

    • @AetherMomon
      @AetherMomon Před 4 dny

      @@DevGods Thanks for the answer! I was looking through the code for the State Tree plugin, I can’t understand most of the code but from what I could see I was afraid that I would have to customize the plugin itself in order to make custom states & transition types. It would seem that is the case. I don’t want to modify any engine plugins so unfortunately that’s not an option, I do wish they would have made the State Tree plugin more overridable and customizable in C++. It would have been super useful. But I think at this point I’ll need to try to create my own custom solution instead. Most likely I’ll need to create a simpler solution that uses the same core principles as State Tree and is more overridable & customizable in C++

    • @DevGods
      @DevGods  Před 4 dny

      @@AetherMomon You can actually copy the plugin into your projects plugins directory. Luckily state tree has no dependencies. When in your project folder your version will take over the main one. I've actually done something similar for my ability system plugin based on state trees. I still haven't added state presets yet but its on my todo list. Let me know if you get it working.

    • @AetherMomon
      @AetherMomon Před 3 dny +1

      @@DevGods Thanks, that’s very useful! I didn’t know copying the plugin into my project would take over the main one. I will have to look into that then, though I have no experience with editor modules so it might be difficult for me. But I will let you know if I happen to get it working!
      It’s interesting that you’re creating an ability system based on State Tree, it’s an interesting way to utilize State Tree. I have plans to use an ability system alongside State Tree.

    • @DevGods
      @DevGods  Před 3 dny

      @AetherMomon Ha yeah editor programming is confusing as hell at first but I have faith in you. Your idea is cool. For me it’s just an unfortunate situation. Network prediction requires your code to be written a certain way which has a TON of boiler plate. I wanted to make a generic way to make abilities without having to touch all that boiler plate for both myself and any team members. I first used Flow Graph as the UI/UX but it was too limiting. I also tried creating my own graph editor. State trees has a really good core to extent to your needs so I just went with it. It’s been pretty great so far.

  • @DuneGames
    @DuneGames Před 4 měsíci +1

    Appears my other comment got deleted - was it the link to the image of what I'd done?
    Anyway, I was having an issue related to switching states while other state was running. Adding a delay just before the call to set state tree, (which in my c++ code called StopLogic, Set the new tree, then restarted the logic), made it work for me. Thanks, this is great.

    • @DevGods
      @DevGods  Před 4 měsíci

      If you can join the discord and make a forum post. You can post pics and code so I can help

    • @DuneGames
      @DuneGames Před 4 měsíci

      @@DevGods I was going to, but your discord link in the description says for off-topic discussions. I may in the future as I dive into the state trees. The whole idea of having multiple state trees is really going to help. I've heard other youtubers say that doing so would be great but never mentioned how.

  • @robertadams3925
    @robertadams3925 Před 2 měsíci +1

    About half way thru this and running into issues with my custom schema in my enemy character blueprint being unable to recognize my custom patrol state tree. Not requesting you help me troubleshoot, but i does raise a better question:
    Can you describe why using cpp and making a custom schema is advantageous, and what you're able to do here that you wouldn't be able to do otherwise just using state trees out of the box with blueprints only? Im about to give up on cpp implementation and push forward in BP because I know how to get them working in BP, could you speak for a moment on this?

    • @DevGods
      @DevGods  Před 2 měsíci +1

      I program everything I can in c++ it’s just a preference. There are many advantages for using c++ over bp but if it’s a nuisance get it working in BP then migrate over. My channel is focused on building out scalable systems and imho c++ is the foundation for that.
      You are probably running into the issue where the state tree component has specifically set the allowed schema on its “StateTreeRef” to only be state tree schema if you want to set your custom schema’d state tree in your character’s state tree component in blueprints you either need to do it with a custom c++ function that takes a state tree as a parameter or create your own variable, override the initialize function in the state tree component and set the state tree ref to your state tree variable then in bp you can set your variable to be whatever you want.
      The reason you have no problems in bp is because you epic expects you to use only one schema which is the one compatible with the component.

  • @PsychotropicDog
    @PsychotropicDog Před 16 dny +1

    And I found myself annoyed that UE 5.4 still does not have 'Set State Tree'. It is worth it to learn some C++ just to do this custom State Tree with the one function that should already be there in blueprints. (around the 35 min mark)

    • @DevGods
      @DevGods  Před 16 dny

      I’m pro c++ everyday all day. It will only make things better for you in the long run. You’re going to end up needing it eventually and then you’ll be mad at yourself for not doing it sooner. I wasted 8 whole months avoiding it. I regret that every single day.

    • @PsychotropicDog
      @PsychotropicDog Před 13 dny +1

      @@DevGods I am not anti C++, but I have other suites to explore. There was a link to another obtuse resource from Epic, that wants to send me on a fetch quest for the simplest things.

  • @dead7643
    @dead7643 Před 5 měsíci +1

    I'm trying to make the same OurStateComponent, but with the ability to use parameters. Do you have any ideas on how to do this?

    • @DevGods
      @DevGods  Před 5 měsíci

      This is a broad and very vague question. If you want to use parameters then add them.

    • @dead7643
      @dead7643 Před 5 měsíci

      @@DevGods I want to pass not only the tree, but also its parameters in the SetStateTree function. But FInstancedPropertyBag (parameters) are not available in BP

    • @DevGods
      @DevGods  Před 5 měsíci +1

      @dead7643 if it’s not a blueprint accessible struct all you need to do is create one that is and have that one create the c++ version. If you are following this in blueprints only I really don’t know.

  • @rangerRick9895
    @rangerRick9895 Před měsícem +1

    Hmm mine crashes on event exit state 14 min in. Event ExitState is called more than once. On the second loop it crashes... On dead state I trigger "On State Completed" transition To "Tree Succeeded". Anyone else having this problem on 5.4?

    • @DevGods
      @DevGods  Před měsícem

      Do you have debugging symbols installed? You should join my discord and post the crash log in the divine forum channel

  • @xSp33dy97
    @xSp33dy97 Před 4 měsíci +1

    The state trees with the custom made OurStateTreeSchema don't appear in the details tab for OurStateTreeComponent, any idea why? But if I change it to the default Schema it appears. For the SetStateTree function made it appears

    • @DevGods
      @DevGods  Před 4 měsíci

      That’s a schema thing. Like I said early in the video the schema is a filter. You can make your own. Check out the state tree schema for an example. Remember that the engine is source available if you see that something works a certain way and yours doesn’t you can dive into it and see what differences there are.

    • @xSp33dy97
      @xSp33dy97 Před 4 měsíci +1

      Been looking on both UStateTreeSchema from the engine and UStateTreeComponent and I don't see it being filtered anywhere but in the UStateTreeComponent where StateTreeRef property is created and it has between () meta=(Schema="/Script/GameplayStateTreeModule.StateTreeComponentSchema") not sure what this does though.

    • @DevGods
      @DevGods  Před 4 měsíci

      @xSp33dy97 jump into my discord so I can show you mine

  • @PsychotropicDog
    @PsychotropicDog Před měsícem +1

    most XLNT

  • @dead7643
    @dead7643 Před 5 měsíci +1

    5.3?