Drag and Drop ENEMY AI With Scriptable Objects in Unity

preview_player
Показать описание
Learn how to setup Enemy Brains or AI Behavior using Scriptable Objects allowing you to easily drag and drop new ai behavior through the Unity inspector.

Scriptable Objects are a powerful tool in structuring your code cleanly, and here is no exception. With this approach you can setup a complex enemy a.i. behavior tree while all of the behavior logic is separated into individual scriptable objects.

This follows the delegate pattern, which enables separation of concerns amongst your scripts which is an important practice in producing clean, maintainable code that will see your project through to the end.

Also its fun to play around with enemy "brains".

✨Want to support the channel?

SUBSCRIBE or else I'll play around with your brain

➤LIKE the video if you enjoyed, it really helps the channel!

We have channels to help you with your problems!

Thanks for watching!

#bmo #unity #tutorial
Рекомендации по теме
Комментарии
Автор

Dood I was literally making a game rn, and figuring out how can I use scriptable objects to organize my enemy ai behaviors . Then this video got recommended to me like youtube is reading my mind and I realized this video was just uploaded 5 hours ago lol . What's more funny is I just subscribed to you like 15 hours ago.
Anyways, keep up the good work man !!

clarencetinator
Автор

Bmo big brain 🧠 super helpful AI tutorial!

mandamoon
Автор

I've just used this idea to remake the AI in a game project. What we expected to take a month to rebuild. We did a working base in less than 2 days. Best idea ever to make modular behaviours. Old AI was over 1500 lines. The new one with all behaviours so far combined 260 lines.

Update. We still use this system as base for our new Enemy AI, but with all the stuff we've covered we found out a few little limits.

Pro:
-Making modular AI behaviours easy to switch with another.
-Specific behaviours for specific enemies.

Con:
-You can't use Async or IEnumerator in a scriptable object. They do work but for exemple 2-3 enemies die at the exact time, only one will trigger the Async or IEnumerator. You need to put them in the main script and use the the scriptable object behaviours to call it.

-Start and update function doesn't exist in scriptable obj. Possible to create a ''fake'' update function called from the main script calling the update on the active behaviours.

FyresGames
Автор

You deserve so many more subs!
Great video

eileeng
Автор

Honestly if I hadn't been subscribed already, that last bit would've earned it regardless haha! Keep up the good work and sense of humor! I have learned a great deal from your tutorials already!

SamProgress
Автор

Great vid as always! This is my fave way to do AI in unity. You can also pass the target directly as a parameter. I also like to pass "context" (list of surrounding objects) as a parameter to allow boid like behaviors ☺

stefan
Автор

Thank you for the tutorials. Making my way through them all, including the occasional BMO "Ted Talk" videos.

ibelonghere
Автор

Thank you youtube recommended for this blessing.

HeirophantOurple
Автор

This seems really good! I will try it. If I want to create different behaviors and have conditions for switching between them, would you contain the logic for switching between states within each scriptable object?

GamePhysics
Автор

Nice video! Thanks a lot for the tutorial, now my enemy becomes very flexible. But one problem tho, when I duplicate the enemy, all of the enemies suddently becomes very weird, but when I duplicate the behaviours, all of the enemy works fine. Is this becouse a behaviour act as all of the enemies brain? If so is there any way that I can make the enemy to have different brains without having to duplicate everything?

NicDev
Автор

How do you make it that you want the enemy to go for an objective but if the player gets inside his range he go for the player and if the player ran (out of his range) he goes back to his objective?

There is also when the enemy collides you can just push him back and it just does not chase you anymore.

Nitys
Автор

Does this concept replace the need for a State Machine then?

inkofthedragon
Автор

Thanks! I didn't think you could use those with AI.

suicune
Автор

muito bom, justamente oque eu estava procurando.

sr_viny
Автор

Once again another amazing video !?! I was just wondering if you have any videos on this... I have a pick up item (call it a perk) that give me a super jump automatically.... but I wanted it so u could scroll through different perks and then picking one to enable the super jump... if that makes sense.. kinda like a weapon list but for a perk lol

NotSoSeriousGaming
Автор

I don't like this system because of the assets duplication (base script + scriptable object per single behavior), but I use scriptable objects for stats management and let machine states or behavior nodes do the actual behavior, that's probably a way less cluttered method if you don't mind dealing with code to "register" each enemy behavior in a dictionary so they can be found by a name passed in a manager class

lazydude
Автор

Nice video, however I really don't understand the difference with scriptable object vs regular scripts?

It's just using an abstract class which we are inhereting from. This can be done using regular scripts.

How is inhereting from scriptable objects different?

(really trying to grasp it😂)

durrium
Автор

good video, thanks. But, lots of using FindgameObjectswithTag and GetComponent in every Update call

Balakademi
Автор

Neat concept, but calling GetComponent in Update makes my brain hurt (pun not intended). Don't do that if you care about performance.

synchaoz
Автор

Running "find object by tag" inside "think" which is called every frame inside an Update function call? I don't see how this degree of abstraction is helpful (the example is too simple) and surely running gameobject.find on the update call of every enemy object is very wasteful? I just don't get it. I bailed at 7:30 once it became clear you were calling find so often - this could kill a game with lots of enemies?

ChrisHolden