- Home /
Unity Steer - Setting Quarry in Steer for Pursuit problem
Hi,
At present I have instantiated enemies with very basic AI. They spawn, they run at the player. End of story.
I want to overhaul my enemies using Unity Steer so that they avoid buildings/obstacles and each other, but I've run into a problem.
As my enemies are instantiated from prefabs rather than already in the scene, I seem to be unable to set my 3rd Person Controller (The Player) as the Quarry when using Steer for Pursuit. If I place an enemy on the level I can do it, but not if it's a prefab.
I've tried also making my 3rd person controller a prefab and setting it to that but that didn't work either.
Any help would be much appreciated.
Answer by Jesse Anders · Jan 17, 2011 at 06:52 PM
I'm going to guess that you're trying to assign a reference to an object in the scene to a field of a script associated with a prefab.
If so, this won't work. Think about it this way. Prefabs exist outside of any particular scene. If a reference associated with a prefab points to an object in a particular scene, where will that reference point when a different scene is loaded? The object it points to won't even exist at that point.
What you'll most likely need to do is assign the player reference when the AI agent is instantiated. There are several ways this can be done; one would be to assign the reference immediately after instantiation using the return value of Instantiate(), and another would be to search for the player by name or tag and grab a reference in the Awake() or Start() function of a script associated with the AI agent.
Thanks, I think I understand what you mean about the prefabs existing outside the scene.
I'll have a go at what you suggest and report back!
Hmmm.
Well, I've come into a problem with it. I've decided to try and search for the player by tag, but I'm getting the error "Cannot implicitly convert type 'UnityEngine.Transform' to 'Vehicle' or vice versa depending on which way I try to do it in the SteerForPursuit script.
Are you familiar enough with Unity Steer to offer any insight into a way around that? I could post the whole script if it's useful?
Never$$anonymous$$d, solved this with some other help! Thanks for your input!
Can you let me know what you did? I am running into this issue with trying to send GameObjects to SteerForPursuit when they expect DetectableObjects.
Your answer
Follow this Question
Related Questions
Unitysteer - Rigidbody with gravity stops steering 2 Answers
UnitySteer SteerForPursuit: How do you Change quarry After the current quarry gets destroyed 0 Answers
Help with kinematic NPCs following non-Kinematic player and avoiding obstacles 0 Answers
Camera rotation around player while following. 6 Answers
Objects not following 1 Answer