Forum rules - please read before posting.

Instantiated Character Problems

edited May 2018 in Technical Q&A
I am having a problem where my NavMesh Agent based Player walks further than he should when moving to markers, but only when instantiated. If he is present in-scene, then there is no problem.

There is also a worse problem: If the character is instantiated, then for some reason, actions for altering animator parameters won't work. But again, if the character is already in the scene, it works just fine.

Note that I chose to use the NavMesh agent because without it, the character has serious problems with pathfinding.

I also get this when the character is spawned:

Failed to create agent because it is not close enough to the NavMesh
UnityEngine.Object:Instantiate(Player, Vector3, Quaternion)
AC.KickStarter:ResetPlayer(Player, Int32, Boolean, Quaternion, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:860)
AC.KickStarter:OnAwake() (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:989)
AC.MultiSceneChecker:Awake() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:47)

This is in Unity 2017.1

Adventure Creator 1.62.2

This project uses Point & Click movement in a 3D environment.

Any help appreciated.

Comments

  • For now, I'd recommend leaving the character in the scene file in that case.

    Where is your NavMesh in relation to the origin of the scene?

    The animation issue may be Unity related.  What's the state of the Animator at this time, and are you getting any relevant messages in the Console?

    If you're having serious problems with the default pathfinding, please share details so they can be looked into.
  • I am able to see the error appear, but it has no apparent effect so far as I can tell - both the animation playback and agent movement work as expected in my case.

    In addition to answer to the questions above, please try to provide steps for the problem to be reproducable - or a test package (scene, managers, player prefab) to try out.
  • Thanks for looking into it.

    So, the NavMesh. When you say "in relation to the origin" do mean origin as in 0,0,0? If so, then it is quite a way off in every axis, though I wouldn't have though it would make a difference - I may be wrong of course.

    The animation issue: For some reason, it will only set booleans to true for in-scene player characters. What's supposed to happen is, after an inventory combination, the player is switched to a different character (using the same animator), a boolean is set to true, which transitions from an idle state to a different idle state (holding a gun), which then is supposed to set another boolean to true which "aims" the gun when he walks to a marker. And it DOES, but only if the player is already in the scene...

    Pathfinding without NavMesh Agent: I find this a lot less reliable than navmesh agent characters, to the point where the player character can barely even find his way around a corner without walking into it for five minutes. General movement is also affected, he struggles to climb the smallest of stairs for example. Locomotion animation generally looks better though - with navmesh agent integration it's a little bit "glidey" but at least it's less frustrating and more reliable this way. I've also been able to walk through walls using the default pathfinding method.

    https://imgur.com/AFN7av7

    An image of the animator

    Let me know if there is something else I can tell you

    Cheers
  • Not much to go on from this.
    • What happens exactly if the player is spawned with regards to his animation?  Is his Animator's Controller field assigned?  Do his normal "Walk speed float" etc animations play?
    • Are you able to manually change the parameters at runtime by opening up the Animator window when the character doesn't animate correctly via AC?
    • What, if any, animation-related messages appear in the Console?
    • As a test, try adding a small piece of NavMesh at (0,0,0).  Does that improve the NavMeshAgent's behaviour?
    • Without seeing any detail about the "vanilla" pathfinding, I can't suggest much other than reducing your Agent Radius when baking, and replacing your Rigidbody/Capsule Collider with a Character Controller, which is better suited when stairs/slopes are involved.
  • edited May 2018
    Good news!

     The animation states weren't changing because of the order I had the actions in the inventory item combination action list asset. Before, I had it setting a bool (animator parameter) then changing player character. When the player was switched, the new one didn't "remember" that the parameter had been changed, and so further animations would not play because they relied on that boolean being set in order to transition (that's also why he was walking too far - wrong walk animation being used). The solution was just to set it after switching player.


    btw When I find time, I will look deeper into the "vanilla" pathfinding issues.

    Cheers
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.