If I go through portals, some enemies no longer have a walking animation?

First the player didn’t have any walking animations anymore, after restarting Unity I thought everything was working again, but now some enemies have no walking animations anymore.

But that only happens after I go through a portal at least twice.

An enemy can also no longer make an attack and cannot be attacked.
And another can attack, but without attack animation.

The enemies are all the same prefabs.

When you say “at least twice”, so you mean
Scene 1: Everything is normal
Portal to scene 2: Everything is normal
Portal back to scene 1: Some enemies are no longer animated or can no longer attack
Portal back to scene 2: Some enemies are no longer animated or can no longer attack?

I see you’re posting this against a video in Scene Management, but have you already implemented the saving system in one of the next two sections?

Yes if I go from scene 1 to scene 2 and back to scene 1, there is the problem.
No I don’t have the saving system, the portal video is the latest video.

Does the saving system solve such things?
Then I just continue in the course, it’s a lot of fun this course, I work a few hours every day on the game.
I never thought I could make a game like this myself.

No, I’m not sure what’s going on with this… without the saving system, you should get the starting state of the scene every time. Whenever a scene is loaded, everything is set to the state in the file.

Paste in your Portal.cs and let’s see if I can figure anything else, but this may need to be escalated to Unity customer support.

Now I integrated the saving system and the error still exists.

I am also of the opinion that the scene is completely reloaded and that such an error should not actually occur.

Here is my Portal.cs file, I have this project in a private GitHub repository, if you want i can make the repository public and send the link to it.

For this project I use Unity 2021.3.1f1

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;

namespace RPG.SceneManagement
{
    public class Portal : MonoBehaviour
    {
        enum DestinationIdentifier
        {
            A, B, C, D, E
        }

        [SerializeField, Range(-1, 100)] int sceneToLoad = -1;
        [SerializeField] Transform spawnPoint;
        [SerializeField] DestinationIdentifier destination;
        [SerializeField] float fadeOutTime = 0.5f;
        [SerializeField] float fadeInTime = 1f;
        [SerializeField] float fadeWaitTime = 0.5f;

        private void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.tag == "Player")
            {
                StartCoroutine(Transition());
            }
        }

        private IEnumerator Transition()
        {
            if(sceneToLoad < 0)
            {
                Debug.LogError("Scene to load not set");
                yield break;
            }

            DontDestroyOnLoad(gameObject);

            Fader fader = FindObjectOfType<Fader>();

            yield return fader.FadeOut(fadeOutTime);

            SavingWrapper savingWrapper = FindObjectOfType<SavingWrapper>();
            savingWrapper.Save();

            yield return SceneManager.LoadSceneAsync(sceneToLoad);

            savingWrapper.Load();

            Portal otherPortal = GetOtherPortal();
            UpdatePlayer(otherPortal);

            yield return new WaitForSeconds(fadeWaitTime);
            yield return fader.FadeIn(fadeInTime);

            Destroy(gameObject);
        }

        private void UpdatePlayer(Portal otherPortal)
        {
            GameObject player = GameObject.FindWithTag("Player");
            player.GetComponent<NavMeshAgent>().enabled = false;
            player.GetComponent<NavMeshAgent>().Warp(otherPortal.spawnPoint.position);
            player.transform.rotation = otherPortal.spawnPoint.rotation;
            player.GetComponent<NavMeshAgent>().enabled = true;
        }

        private Portal GetOtherPortal()
        {
            foreach (Portal portal in FindObjectsOfType<Portal>())
            {
                if (portal == this) continue;
                if (portal.destination != destination) continue;

                return portal;
            }

            return null;
        }
    }
}

At this point, the saving system is only going to mask the symptoms, leaving us unclear of the cause.
I think I will have to take a closer look at your project.

Rather than dealing with public/private, zip up your project and upload it to https://gdev.tv/projectupload
Be sure to remove the Library folder to save space.

Thanks for the great support, I uploaded the project.

Ok, this looks like one of those strange quirks that Unity has from time to time when there is another animator in the tree…

In this case, there is an Animator at the Player component, as well as an animator on the Character_Knights_Soldier prefab sitting under the Player. Sometimes the secondary animator (the one on Character_Knights_Soldier) imposes it’s will over the one on the Plaer. Delete the one on the Character_Knights_Soldier prefab and this should put the issue to rest.

1 Like

Thank you for the help, I will do that.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms