you may want to read the edit at the end first @edc237
I had some confusion with this when I set up my project for the merge. I had two NavMeshSurfaces. I thought I had skipped removing the one from the old version. It didn’t seem to be an issue, but I went around in circles for awhile. Turned out I had added a surface to two different objects in the scene. From the list above, it looks like you do too. This is not a problem. It is how you can make larger characters be blocked by narrow things. It’s pretty cool, actually.
lol at this point in time, I’m thinking of one idea only:
if it ain’t a big boss that’ll need to be blocked by Navigation Mesh objects, then don’t touch it lah… In other words, split the NavMesh only when necessary (in this scene it probably won’t be, so I’ll let it be for now)
OK let’s try not get into the new NavMeshAgent system as of yet, as that sounds like a major headache for now… any other simpler solutions? (I recently discovered a brand new bug with my NavMeshAgent, and it’s… quite annoying):
- Sometimes when I dismount my horse, I teleport to somewhere else (I told Malbers about this, but he’ll probably respond by midnight, that’s like 7hrs away)
- Sometimes when I’m gathering resources, for god knows what reason, I also teleport to somewhere else…
It’s an occasional bug, with no errors, but I’m guessing it has something to do with the NavMeshAgent…?
I am at work right now so I can’t check, but I think you should not have a NavMeshAgent on the player at this point. I will look at Brian’s repo later today if no one responds before then.
I did indeed delete that as soon as you mentioned it… for now it SEEMS to be gone, but only further testing over time will tell me
For now, you just need ONE NavMeshSurface, and of course, it needs to be baked. You should be able to see the NavMesh in the Scene view when you select the GameObject you put the surface on.
Note that if you’re doing the “placing objects in the scene at runtime”, the Prefab should have a NavMeshModifier on it (not a surface, or a NavMeshModifierVolume).
As to why it’s breaking the Crafting system, I would have no idea whatsoever.
that’s just for the trees and rocks, because having them static in the scene does not destroy them when they’re out of resources… beats the purpose of having them reload for some time
don’t we need to do that for literally every single gameObject in the scene…? There’s a reason why I’m scared to touch that now (my scene has a lot of GOs…)
ahh… I went back to my latest clean copy to fix that
GameObjects that aren’t going to be changed generally don’t need a NavMeshModifier, as the Surface picks them up when you bake it just like the legacy NavMesh.
why is it that everytime I touch that NavMeshAgent, some disaster happens in my project…?!
This time, I can’t respawn to my spawning point, which is on top of the NavMeshSurface-containing GameObject
And why can’t I respawn? Because I deleted my NavMeshAgent off my player apparently… I did that because at first it avoided teleportation issues when my player was doing tasks like dismounting a horse or cutting trees
BUT DELETING IT MEANS RESPAWNING NEVER HAPPENS…!
How do I delete with this?! I want to eliminate my players’ NavMeshAgent (to avoid him teleporting when dismounting, cutting trees, etc), but I also need to be able to respawn @Brian_Trotter (I tagged you because the edited comment has changes)
There is undoubtably an error message… does it have anything to do with the NavMeshAgent being null?
yes it does, it does have something to do with “ResetPath” and “SetDestination”:
"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:SetDestination (UnityEngine.Vector3)
RPG.States.Enemies.EnemyPatrolState:Enter () (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyPatrolState.cs:61)
RPG.States.StateMachine:SwitchState (RPG.States.State) (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:13)
EnemyIdleState:Enter () (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyIdleState.cs:17)
RPG.States.StateMachine:SwitchState (RPG.States.State) (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:13)
RPG.States.Enemies.EnemyAttackingState:Tick (single) (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyAttackingState.cs:54)
RPG.States.StateMachine:Update () (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:18)
"ResetPath" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
RPG.States.Enemies.EnemyPatrolState:Exit () (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyPatrolState.cs:115)
RPG.States.StateMachine:SwitchState (RPG.States.State) (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:11)
RPG.States.Enemies.EnemyPatrolState:Tick (single) (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyPatrolState.cs:77)
RPG.States.StateMachine:Update () (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:18)
"ResetPath" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
RPG.States.Enemies.EnemyChasingState:Exit () (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyChasingState.cs:53)
RPG.States.StateMachine:SwitchState (RPG.States.State) (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:11)
RPG.States.Enemies.EnemyChasingState:Tick (single) (at Assets/Project Backup/Scripts/State Machines/Enemy/EnemyChasingState.cs:28)
RPG.States.StateMachine:Update () (at Assets/Project Backup/Scripts/State Machines/StateMachine.cs:18)
When I delete the NavMeshAgent off the player, these 3 messages keep repeating themselves pretty much forever, and the screen stays permanently black (so basically if you die, the entire game dies with you… quite the punishment )
All three of these errors relate to the enemy state. Why would the player having a NavMeshAgent or not affect the enemy state?!? This is most peculiar.
believe it or not, I am as confused as you are, but… that’s what I am getting for some reason
He has his own State Machine, but somehow deleting the players’ State Machine causes these types of errors for some reason
OH and it also has this error hidden, but that one went by so fast I didn’t even notice it the first time…:
MissingComponentException: There is no 'NavMeshAgent' attached to the "Player" game object, but a script is trying to access it.
You probably need to add a NavMeshAgent to the game object "Player". Or your script needs to check if the component is attached before using it.
UnityEngine.AI.NavMeshAgent.Warp (UnityEngine.Vector3 newPosition) (at <0afbda7469054715a6c81ca1d5a5df8f>:0)
RPG.Control.Respawner.RespawnPlayer () (at Assets/Project Backup/Scripts/Control/Respawner.cs:111)
RPG.Control.Respawner+<RespawnRoutine>d__8.MoveNext () (at Assets/Project Backup/Scripts/Control/Respawner.cs:62)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <ba783288ca164d3099898a8819fcec1c>:0)
I think you have other systems in your project that require the player to have a NavMeshAgent. Some how you need to resolve this conflict. I would look at every system and find where the player navmesh is used and try to eliminate them. I have no idea if that is possible with your horse riding, tree mining, respawning, etc., etc. That last error message you posted has several references to specific things you can check for NavMesh issues. It looks like your respawner is trying to warp the player.
You don’t really mean that you deleted the PlayerStateMachine do you??!!?? That would definitely break a lot of things!
NavMeshAgent my bad…
for the respawner, I know there is one, and here is what the line looks like:
// 1. placing (Warping) the player back to his original respawn location:
// (it's done in a Coroutine so we can give the player some time rather than instantly respawning)
GetComponent<NavMeshAgent>().Warp(respawnLocation.position);
I’m just not sure if deleting that and replacing it with a line like this one:
this.transform.position = respawnPosition; // i will find a way to declare 'respawnPosition' later
would pull off the trick or not
As for the horse, I only copied the important parts of the ‘Mover.cs’ scripts’ saving system and called it a day (and it seems to be working just fine…):
using GameDevTV.Saving;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(JSONSaveableEntity))]
public class MountPositionSaving : MonoBehaviour, IJsonSaveable
{
public JToken CaptureAsJToken()
{
return transform.position.ToToken();
}
public void RestoreFromJToken(JToken state)
{
transform.position = state.ToVector3();
}
}
funnily enough, this solved the problem… (unless Brian has a different say on the efficiency of this on the long term):
transform.position = respawnLocation.position; // replaces the 'navMeshAgent.Warp() function'
Good job fixing that!! (9,000 mile virtual high five). Now if someone more experienced than you or I would explain the connection between the enemy state machine and the player’s NavMeshAgent all would be right in the world.
lol you and Brian are both in the states, right? High five to the both of you from Al Ain (or Dubai for simplicity, if you will ), they’re only 120 kilometers apart, xD
I thought you were in Malaysia. Back in UAE are you? It is hard to keep up with you on so many levels!