AI That Learns from mistakes

Is it possible to make a AI that learns from your mistakes and can set down traps, set up cameras. I cannot find a tut to make that kind of AI. Is it blueprint or c++? Thanks

thats pretty high level stuff. your not likely to find a tutorial on it that is specifically in ue4. i know theres whole youtube channels about ai learning so do some googling and learn their methods and algorithms you may have to do the coding yourself though.

Yes, although it depends exactly what you want.

If you want it to ‘truly’ learn from it’s mistakes and adapt dynamically then this will probably be a very complex system and you’ll probably need to write most of it yourself (there may be some libraries you need to use). I certainly wouldn’t suggest attempting this with blueprints, although it might be possible (but slow).

However, the alternate and usual “game” way of handling this is to look for specific triggers / patterns performed by the player and if they are seen, your Behaviour Tree can trigger some other action. For example, it could know if a character kept going down a certain passageway (by setting up collision triggers) and if that occurs a certain number of times, the behaviour tree might then instruct the AI to go and set a trap in that passageway,

This second way gives the illusion of learning, although it’s really only adapting based on pre-programmed rules. Probably enough for most games and will probably give a more satisfying “game play” than any real AI learning system (at least for now). This will still be quite complex to create though and I recommend writing down everything you want it to achieve before you start implementing anything.

I want the ai to set up a bear trap at the front door or windows, board up windows and put a chair up against the door. Also I want it to search inside cupboard and under bed. If the player is hiding in these places he will kill them, if he checks and the player isn’t there he will just leave. Btw Thx for the answer

Yes, It is very possible using workarounds.
You can set up this “intelligent” ai by using simple “if” statements around player behaviour etc. For example, every time the player hides, save a vector with that location and the number of times he goes there if it is the same location. If the player hides there 3 times or more, make the AI go to that location to check it. Same deal with the windows/doors. Check how many times the player goes through that window/door (Use triggers/collision). The more the player goes through that window/door, the higher chance the AI will board it up. There is no single tutorial that will help you do this, but it is possible using multiple systems.

Let me know if this is helpful!

Thanks I will try this

Could you do a small tutorial on what you mean I am a bit confused on what to use and where to put it. Sorry

That doesn’t sound too much like learning from mistakes, so I think you can absolutely do what you want. I’d strongly recommend using Behavior Trees for this. These help provide a set of rules for your AI, but they are quite flexible.

A bit more information about Behavior Trees in Unreal can be found here: https://docs.unrealengine.com/en-us/Engine/AI/BehaviorTrees

I recommend being patient. Nearly everyone who is new to behavior trees will get it wrong the first few times because it requires a certain way of thinking, Start small and build up!

Its not UE4 but this Unity video includes a project for download. see 54:29.
I assume it is C# but you could take it’s logic and transfer it into Unreal.

It is very interesting stuff!

Hope it helps.

Here are some blueprint examples.

You will need to set up a savegame object and make some variables inside it. The above script is for the window/hiding place, as you can use triggers and check if the player is inside it.(OnComponentBeginOverlap). If they are, it will use some logic to save that location and the number of times. You could replace the vector with a reference to the window/hiding place.

This is for the AI to check the hiding place, by going to it. You will need to make your own script for boarding up windows or opening doors, but this should go a long way for now.

I have not been able to try this, so let me know if it works!

Thanks I will try this :3

Just tried to do that I am stuck however how did you do the two variables in one target and name I cannot find it. Sorry I am so excited to try this but it won’t work if I don’t do that

Go to your savegame and make a variable. It could either be a vector (the one I have shown) or an actor reference (takes a bit more setting up). Then click on the yellow oval next to the type of variable, and select Map/Dictionary (the last one). Then make the right variable an integer. Let me know if the system works!

244230-17.png

244251-18.png

So are these nodes for the ai character or trigger box also how to do set variables

When you drag a variable from the left side, it will give you the option to either get or set the value of it. You can also right click in the event graph and type “Get/Set (variable name)”. In this case, drag out a pin from the savegame and write “Get location” (or whatever the name of the variable is). The first image is for the trigger, but the second image is for the AI. and the 3rd/4th images are for the savegame. So you would need to drag out a pin from the “Get” of the location and write “add” to come up with the “add” node (the first image).

Hope this helps!

ok thx. Btw how did you combine the target and location into one variable?

Pls reply soon

Nvm about the combination of variables I solved it thx anyway

It did not work

I am using AI perception not pawn sensing, and I am also using behavior tree. maybe that is why it’s not working because you used a AI moveto I don’t have that in my AI