Any ideas on a simple AI script that doesn't use any drag/drop variables

So I have a spawn script that uses instantiate to spawn an enemy prefab. However the AI script on the enemy uses the position of the player within the hierarchy and instantiated prefabs do not keep these variables. does anybody have any advice on how to create an ai script that doesn’t use this but still moves towards the player?

If your player object has a tag, you can use


to get the first found object with that tag. If you are using the “Player” tag, and make sure that there is only ever one object with it, it should work fine.