I realised that I had modified the StateMachine class and added a GetGizmoColor that I don't show in the video. This to make it easier to debug, so do as you please. Here is the code that would go into StateMachine.cs: public Color GetGizmoColor() { if (currentState != null) { return currentState.GizmoColor(); } return Color.grey; }
please help NullReferenceException: Object reference not set to an instance of an object EnemyState_RunToCover.OnEnter () (at Assets/Enemy/Enemy Scripts/EnemyState_RunToCover.cs:20) StateMachine.SetState (IState state) (at Assets/Enemy/Enemy Scripts/StateMachine.cs:36) EnemyBrainV2.Start () (at Assets/Enemy/Enemy Scripts/EnemyBrainV2.cs:32) ive followed yout tutorial till the 27 min mark and have ebeen stuck sorting out errors for about 8 hours now finnaly down to 1 and i cant understand as to why im getting this problem i have done everything you have mentioned but yet still no progress
@@REALHARIBO the issue here is a reference is null, so either a variables os not initialised or you did not link all the things in the editor. My guess from your error pasted, is the CoverArea is null but could be something else
As someone who's been self teaching game dev as a hobby it's really refreshing to find content that focuses on not just how to achieve a result, or implement something in the most basic sense, but instead focus on how to achieve a result that's good, or implement a feature with polish. I'm pretty sure i've learnt most of the basic implementation methods, so thank you so much for taking the time to create such high quality videos that are for a more intermediate/advanced audience.
This is a really high quality content, not only is everything explained really well theoretically and demonstrated practically, but also you leave us with specific keywords to find out more where relevant. Feels like a paid course, and a good one on that note.
My gawd, i finnaly found this, this is exactly what i needed for my game. Thank you for explaining this in such a basic level, that even i could understand! Big up!
this is exactly what i was looking for. please please please make more. SO many tutorials on here covering the "stupid" AIs but really nothing covering enemies who even pretend to have a sense of strategy
you are not a live saver, you are the embodiment of divine intervention. i was looking to pick up unity to develop a payday 2 type game, where the ai bassicaly just throws itself at the player. you cant even imagine how many tutorials ive watched to try and find what i need. thanks so much man
Great tutorial but one thing I did find an issue with after adding more then one ai you have to do a check if the cover is taken or not or the ai will trip out trying to get in the same position as another. After adding a check for this it worked perfectly.
Yes, with more than one, you probably want a manager / commander that will tell where each agent should go. That can then also be a statemachine with different strategies etc based on the player’s actions :D
Just an FYI. NavMesh 'Helping an enemy find its way to its destination without running into anything' is using an A* algorithm.... which is actually one of the first Ai algorithms people learn.
I just want to say thank you. It is kind of advanced topic and not for my beginner level but I didn't see anyone explain it in your way or event hight light some of these advanced topics. Even if I didn't understand everything I still find it useful and helpful.
Fuck you for being late to post this on the internet 😂. No cap this is *THE* thing i was looking for 1.5+ years, this tutorial is a hidden gem ❤. you earned a subscriber
I've followed through everything but I run into an issue at the very end, it works but the target's position isn't updated every tick like one would expect. If I move around the agent keeps shooting at my initial position
The video became a bit long. I usually aim for 10 minutes. Anyway, I hope you enjoy and let me know what you like and what you hate. I have many more tutorials in the pipeline :D
I was wondering, without access to editable scripts or ability to use new scripts... Is there any way we can use ultimate events to make them seem smarter or exhibit new behaviors?
@@this-is-gamedev Alright. Thank you. The reason I was asking is I'm trying to get some desirable behaviors out of the AI in Bonelab, but those developers thought it was a great idea to not permit their edited SDK for unity and their game to use scripts that weren't included in the base game, so most of us are stuck trying to force ult events to do things that it wasn't meant to do. Technically we do have their base scripts, but no access to see what is inside of them.
Overall a useful tutorial- but it would have been better to see it more compartmentalized. Adding all the animations and such in complicates what was the interesting part of the video which is the enemies behavior.
@@this-is-gamedev for sure! I mean no shade, I don’t have the courage to post videos so either way - it’s your style! I’ve been a dev for a while now but newer to C# and Unity - and I’ve always personally preferred highly specific videos as gluing the pieces together usually isn’t too bad once you know how the individual pieces work. But that’s just me and I know I don’t speak for everyone. Was a very useful video overall
Hey! Great Video but when using this in my schoolprojekt i've run into some troubles. In my scene everything works just fine but as soon as i put the enemys into the main scene they move around for no reason at all. Even when put in the coverstate from the beginnig on they start spinning and moveing around the map. Is there any way you could help me out with this problem?
hey man great tutorial i just ran into this error that my trail render is visible but they tend to go downward rather than following the ray they tend to go to the bottom of the player
3:01 if it blue it good got me so hard 😂😂😂😂 ( btw i really liked the way that he speaks and it is understandable course also he's really cute (i am not gay just being honest) )
Hey man I ran into this new issue, the code error says there is nothing called func for statemachine and also I am getting a new error it says that statemachine don't have get gizmos color function, how can I solve it
thx so much, ur a life saver im using this for a school project, however I came across a little bug start reload gets called but it never reloads any idea why and do u have the scripts anywhere so I can better see the difference
Usually, the enemies act local to a part of the world. You can’t really have tons of enemies active at ones. Or you can. You might have to look into ECS maybe or other ways to manage open world games. But state machine can be used for everything, yes :D
my enemy not following my player there are no errors on console why it just happened to me :"(( i checked everything is correct i have also added player in enemy target and my player has collider so now what should i do, i have created a empty game object in hierarchy and added navmeshsurface component in and i baked and after that everything just fine just like your and i got a problem after backed navmesh detect my player as a obsticles and made border around my player just like other object and i solve by adding layer mask as player and navmesh ignore that it fixed bu still not following enemy my player at 11:46 ?
I don't know what I did but I'm having problems with the project, from EnemyBrain_Smart to EnemyState_Delay, one tells me it's StateMachine and the other is IState, I really needed a little help starts in 25:19 please i need help
Please, I need help: I have 3 errors in the EnemyState_Cover. Assets/Scripts/EnemyState_Cover.cs(4,33): error CS0535: 'EnemyState_Cover' does not implement interface member 'IState.Tick()' Assets/Scripts/EnemyState_Cover.cs(4,33): error CS0535: 'EnemyState_Cover' does not implement interface member 'IState.OnEnter()' Assets/Scripts/EnemyState_Cover.cs(4,33): error CS0535: 'EnemyState_Cover' does not implement interface member 'IState.OnExit()'
Yes, you have to create a new script that implements IState and then where the state machine is create, you create a new instance of your state and make sure it is either the starting state or you transition to that state.
@@this-is-gamedev Jesus christ man im just an artist trying to survive programming subjects but the things they ask sometimes are ridiculously difficult. BTW Great video super interesting!
Mmmm, add some Debug.Log to be sure that 1) all states enter and exit correctly 2) monitor the values that are used to transition from 1 state to another
@@this-is-gamedev heres my enemy cover script i think it is the main problem as i am getting an error that The local function 'Any' is declared but never used using System; using System.Collections.Generic; using UnityEngine; public class EnemyCover : IState { private EnemyReferences enemyReferences; private StateMachine stateMachine; public EnemyCover(EnemyReferences enemyReferences) { this.enemyReferences = enemyReferences; stateMachine = new StateMachine(); // STATES var enemyShoot = new EnemyShootState(enemyReferences); var enemyDelay = new Delay(1f); var enemyReload = new EnemyReloadState(enemyReferences); // TRANSITIONS At(enemyShoot, enemyReload, () => enemyReferences.shooter.ShouldReload()); At(enemyReload, enemyDelay, () => !enemyReferences.shooter.ShouldReload()); At(enemyDelay, enemyShoot, () => enemyDelay.IsDone()); // STARTSTATE stateMachine.SetState(enemyShoot); // FUNCTIONS & CONDITIONS void At(IState from, IState to, Func condition) => stateMachine.AddTransition(from, to, condition); void Any(IState to, Func condition) => stateMachine.AddAnyTransition(to, condition); }
public void OnEnter() { enemyReferences.animator.SetBool("combat", true); } public void OnExit() { enemyReferences.animator.SetBool("combat", false); } public void Tick() { stateMachine.Tick(); } public Color GizmoColor() { return stateMachine.GetGizmoColor(); } }
I realised that I had modified the StateMachine class and added a GetGizmoColor that I don't show in the video. This to make it easier to debug, so do as you please. Here is the code that would go into StateMachine.cs:
public Color GetGizmoColor() {
if (currentState != null) {
return currentState.GizmoColor();
}
return Color.grey;
}
please help
NullReferenceException: Object reference not set to an instance of an object
EnemyState_RunToCover.OnEnter () (at Assets/Enemy/Enemy Scripts/EnemyState_RunToCover.cs:20)
StateMachine.SetState (IState state) (at Assets/Enemy/Enemy Scripts/StateMachine.cs:36)
EnemyBrainV2.Start () (at Assets/Enemy/Enemy Scripts/EnemyBrainV2.cs:32)
ive followed yout tutorial till the 27 min mark and have ebeen stuck sorting out errors for about 8 hours now finnaly down to 1 and i cant understand as to why im getting this problem i have done everything you have mentioned but yet still no progress
@@REALHARIBO the issue here is a reference is null, so either a variables os not initialised or you did not link all the things in the editor.
My guess from your error pasted, is the CoverArea is null but could be something else
You need to drag CoverArea Script to 'Covers' GameObject in hierarchy@@REALHARIBO
@@REALHARIBO I Guess stateMachine = new StateMachine(); is to be initialized in RunToCover State
As someone who's been self teaching game dev as a hobby it's really refreshing to find content that focuses on not just how to achieve a result, or implement something in the most basic sense, but instead focus on how to achieve a result that's good, or implement a feature with polish. I'm pretty sure i've learnt most of the basic implementation methods, so thank you so much for taking the time to create such high quality videos that are for a more intermediate/advanced audience.
Hey thanks! Appreciate it!
Great comment, I feel the same way. I learned a lot, thanks!
Definitely worth the length of the video. Your way of explaining is simply wonderful. It's almost like going to school. Thanks, master!
Thanks Appreciate it! 🤓
better than school :)
This is a really high quality content, not only is everything explained really well theoretically and demonstrated practically, but also you leave us with specific keywords to find out more where relevant. Feels like a paid course, and a good one on that note.
My gawd, i finnaly found this, this is exactly what i needed for my game. Thank you for explaining this in such a basic level, that even i could understand! Big up!
this is exactly what i was looking for. please please please make more. SO many tutorials on here covering the "stupid" AIs but really nothing covering enemies who even pretend to have a sense of strategy
Thanks! That’s the plan :D
you are not a live saver, you are the embodiment of divine intervention. i was looking to pick up unity to develop a payday 2 type game, where the ai bassicaly just throws itself at the player. you cant even imagine how many tutorials ive watched to try and find what i need. thanks so much man
You’re welcome :D I am happy it’s helpful :D
Great tutorial but one thing I did find an issue with after adding more then one ai you have to do a check if the cover is taken or not or the ai will trip out trying to get in the same position as another. After adding a check for this it worked perfectly.
Yes, with more than one, you probably want a manager / commander that will tell where each agent should go. That can then also be a statemachine with different strategies etc based on the player’s actions :D
Just an FYI. NavMesh 'Helping an enemy find its way to its destination without running into anything' is using an A* algorithm.... which is actually one of the first Ai algorithms people learn.
It's more ML than AI, not all ML is AI
I just want to say thank you. It is kind of advanced topic and not for my beginner level but I didn't see anyone explain it in your way or event hight light some of these advanced topics. Even if I didn't understand everything I still find it useful and helpful.
I happy you find it useful! Give it some time and try to use it in a simple way like just 2-3 states to get started.
Thank you for the wonderful explanation, as someone who is eager to get into AI, this is extremely helpful.
Awesome! There is a lot to learn in this subject! Happy if this hells you start!
Vastly useful!.. many thanks for the info.. I needed this to progress :D
Awesome! Good to hear!
Fuck you for being late to post this on the internet 😂.
No cap this is *THE* thing i was looking for 1.5+ years, this tutorial is a hidden gem ❤. you earned a subscriber
Haha, that’s awesome. I am happy it’s helpful :D
프로젝트에서 적을 구현하는 것에 큰 도움이 됐습니다. 감사합니다.
Rockstar must hire this guys.. for the next evolve game think..
Uhhh, He called me dedicated... I'm touched🥺!
I've followed through everything but I run into an issue at the very end, it works but the target's position isn't updated every tick like one would expect. If I move around the agent keeps shooting at my initial position
The video became a bit long. I usually aim for 10 minutes. Anyway, I hope you enjoy and let me know what you like and what you hate. I have many more tutorials in the pipeline :D
Thanks for the class
I was wondering, without access to editable scripts or ability to use new scripts... Is there any way we can use ultimate events to make them seem smarter or exhibit new behaviors?
Event system can help yes, but you will need to write some code, at least to raise the events at the right moment.
@@this-is-gamedev Alright. Thank you. The reason I was asking is I'm trying to get some desirable behaviors out of the AI in Bonelab, but those developers thought it was a great idea to not permit their edited SDK for unity and their game to use scripts that weren't included in the base game, so most of us are stuck trying to force ult events to do things that it wasn't meant to do. Technically we do have their base scripts, but no access to see what is inside of them.
This was really informative. Thanks man.
Thanks!
Overall a useful tutorial- but it would have been better to see it more compartmentalized. Adding all the animations and such in complicates what was the interesting part of the video which is the enemies behavior.
Thanks! That’s true. I’ll see what I can do. Could make another video showing different use cases and just focusing the FSM
@@this-is-gamedev for sure! I mean no shade, I don’t have the courage to post videos so either way - it’s your style! I’ve been a dev for a while now but newer to C# and Unity - and I’ve always personally preferred highly specific videos as gluing the pieces together usually isn’t too bad once you know how the individual pieces work. But that’s just me and I know I don’t speak for everyone. Was a very useful video overall
@@squirrelzarNo worries. I am listening to all feedback and ideas. :D
Thank you. This is what I am looking for.
Nice! Happy it’s helpful :)
12:03 - genius mem
High quality!
Very well done! Thank you
Thanks! I am glad you like it!
Hey man, GREAT Video. Where can i get your code.
Amazing tutorial i just ran into a problem my enemy is reloading but the ducking animation is not playing along with the reloading animation
Thanks! To play both, you need to split them on 2 animation layers and setup the avatar to mask the bones for the second layer
Great tutorial , thanks 🎉
Thanks! 🙏
Thanks for making tutorial for noob like me! :D
This is a fantastic tutorial
Thanks! Happy you like it!
Learn Animancer and you will never want to look back to animator ever again
I’ll take a look. Thanks!
Hey! Great Video but when using this in my schoolprojekt i've run into some troubles. In my scene everything works just fine but as soon as i put the enemys into the main scene they move around for no reason at all. Even when put in the coverstate from the beginnig on they start spinning and moveing around the map. Is there any way you could help me out with this problem?
Hi, thanks! Difficult to say what is the cause, is it maybe a loose rigidbody?
hey man great tutorial i just ran into this error that my trail render is visible but they tend to go downward rather than following the ray they tend to go to the bottom of the player
Thanks!
Mmm, this might be some pivot issue
@@this-is-gamedevthanks man I already solved it it was a code issue
3:01 if it blue it good got me so hard 😂😂😂😂 ( btw i really liked the way that he speaks and it is understandable course also he's really cute (i am not gay just being honest) )
Just Amazing
Hey man I ran into this new issue, the code error says there is nothing called func for statemachine and also I am getting a new error it says that statemachine don't have get gizmos color function, how can I solve it
The gizmo thing can be added, it was an example. The code is in the pinned comment.
Thanks
Did you ever solve the other issue with the func? I'm currently stuck here too
thx so much, ur a life saver im using this for a school project, however I came across a little bug start reload gets called but it never reloads any idea why and do u have the scripts anywhere so I can better see the difference
It might be that the Reload layer on the animator does not have the weight to 1. Or that the transition is not well configured.
@@this-is-gamedev yes that was it thx
Thanks!
You’re welcome :D
What should I do, if I have a big open world? Or I can do the same stuff?
Usually, the enemies act local to a part of the world. You can’t really have tons of enemies active at ones. Or you can. You might have to look into ECS maybe or other ways to manage open world games. But state machine can be used for everything, yes :D
Very good but I can't add nav mesh because I haven't AI in my Unity
What's your version of Unity
Is it possible with version (2022 ,personal)?
I missed that news with 2022. It seems you have to installed from the package manager. It should be called “AI Navigation”
@@this-is-gamedev
Thank you so much..❤
Im from Iran, and there is no one to ask him, and I get lost
Sir you Dummie character is not showing in scene and also on demo and also when pick it up from models to in heirarchy still just showing colliders
my enemy not following my player there are no errors on console why it just happened to me :"(( i checked everything is correct i have also added player in enemy target and my player has collider so now what should i do, i have created a empty game object in hierarchy and added navmeshsurface component in and i baked and after that everything just fine just like your and i got a problem after backed navmesh detect my player as a obsticles and made border around my player just like other object and i solve by adding layer mask as player and navmesh ignore that it fixed bu still not following enemy my player at 11:46 ?
The word you're looking for is "Navigable".
I don't know what I did but I'm having problems with the project, from EnemyBrain_Smart to EnemyState_Delay, one tells me it's StateMachine and the other is IState, I really needed a little help starts in 25:19 please i need help
EnemyBrain_Smart has the state machine inside. You can’t use a transition -> you have to ->
Please, I need help:
I have 3 errors in the EnemyState_Cover.
Assets/Scripts/EnemyState_Cover.cs(4,33): error CS0535: 'EnemyState_Cover' does not implement interface member 'IState.Tick()'
Assets/Scripts/EnemyState_Cover.cs(4,33): error CS0535: 'EnemyState_Cover' does not implement interface member 'IState.OnEnter()'
Assets/Scripts/EnemyState_Cover.cs(4,33): error CS0535: 'EnemyState_Cover' does not implement interface member 'IState.OnExit()'
Does it still work? I can only bak the Mesh in "Navigation Obsolete
"
Yes, just the AI navigation is now a unity package. But its API is the same.
Ok thx
is there a way to add a "patrol function"? i tried everything but it eighter ignores it or the code breaks
Yes, you have to create a new script that implements IState and then where the state machine is create, you create a new instance of your state and make sure it is either the starting state or you transition to that state.
hello , can you help me ? i cant find the link for the bullet tracer ...
Search “liamacademy bullet” it’s the first hit.
ty:)
@@this-is-gamedev
Will this work with multiplayer like photon
Yes. But I am not that familiar with photon, so you have to just intergrate it with whatever photon uses to sync data across clients
bro do u know how to implement G.O.A.P? for enemy or bosses
Didn’t touch GOAP, yet. It’s a lot of work and ideally you will need some custom tools to debug everything, since enemies are a kind of “free”
@@this-is-gamedev Jesus christ man im just an artist trying to survive programming subjects but the things they ask sometimes are ridiculously difficult.
BTW Great video super interesting!
Oh wow. Check LliamAcademy, he has a good series on GOAP
@@this-is-gamedev Will do asap bro thanks a lot.
What is your version of Unity? I am using Unity version (2022, personal) I don't have AI please help me
On unity 2022.2+ you need to install AI navigation package from the package manager.
How do I make it so the enemy can kill the player?
The player needs a health script that detect the bullet hitting them (physical collision) or the enemy tells the player “I hit you” via raycasts
@@this-is-gamedev thanks!
would any of this work/apply in a VRChat world?
If you can write code, you can write state machines
onto my 30th time watching the vid done everything but for some reason the states stop switching after going grey 😥
Mmmm, add some Debug.Log to be sure that 1) all states enter and exit correctly 2) monitor the values that are used to transition from 1 state to another
@@this-is-gamedev heres my enemy cover script i think it is the main problem as i am getting an error that The local function 'Any' is declared but never used using System;
using System.Collections.Generic;
using UnityEngine;
public class EnemyCover : IState
{
private EnemyReferences enemyReferences;
private StateMachine stateMachine;
public EnemyCover(EnemyReferences enemyReferences)
{
this.enemyReferences = enemyReferences;
stateMachine = new StateMachine();
// STATES
var enemyShoot = new EnemyShootState(enemyReferences);
var enemyDelay = new Delay(1f);
var enemyReload = new EnemyReloadState(enemyReferences);
// TRANSITIONS
At(enemyShoot, enemyReload, () => enemyReferences.shooter.ShouldReload());
At(enemyReload, enemyDelay, () => !enemyReferences.shooter.ShouldReload());
At(enemyDelay, enemyShoot, () => enemyDelay.IsDone());
// STARTSTATE
stateMachine.SetState(enemyShoot);
// FUNCTIONS & CONDITIONS
void At(IState from, IState to, Func condition) => stateMachine.AddTransition(from, to, condition);
void Any(IState to, Func condition) => stateMachine.AddAnyTransition(to, condition);
}
public void OnEnter()
{
enemyReferences.animator.SetBool("combat", true);
}
public void OnExit()
{
enemyReferences.animator.SetBool("combat", false);
}
public void Tick()
{
stateMachine.Tick();
}
public Color GizmoColor()
{
return stateMachine.GetGizmoColor();
}
}
@@this-is-gamedev please help bro
Looks correct. Are you sure the animator is correctly setup? That all parameters match. lowercase and uppercase is important
@@this-is-gamedev yeah it was that i forgot to actually start the reload function when the ammo was empty but thx
Great Video But, that yellow background makes people blind... 😵😵😵😵
Thanks. First time I get this feedback! It’s a fair point :D
Smarter every day reference?)
If that’s the case, not done on purpose 😌
merci frerooo
De rien 😉
dunno why but my transitions not work
Check the conditions and check that when you call methods on the animator that the strings match 1 to 1. It is case sensitive
@@this-is-gamedev thanks for help u got one sub from me :)