Player Unique Identifier Affecting Saving System

Hi,

I had an issue during this lesson that my player’s unique identifier was not consistent between scenes. When the game tried to load the weapon from the other scene it wasn’t finding the same player there. So it found the player in the other scene and the currentWeapon wasn’t set yet causing an error.

Did we take measures earlier in the course to prevent the Unique Identifier from being different for the player between scenes? Should the identifier be set in the prefab? Did I make a mistake somewhere? I solved the bug by manually copying and pasting the unique identifier from one scene into the other scene.

Thanks for your help.

We actually type the player identifier in as player (all lower case) but i cant remember exactly where as new and old mash together atm.
I would double check that and see if thats causing the issue :slight_smile:

Is it possible this didn’t make it into the new version of the videos? Should I type it in, in the prefab? Thanks for your help.

I believe it is in the new videos but i believe it could be around lecture 92 or somewhere before there back to 82.
You can just type player into the UUID of the player prefab as if i remember correctly thats how it was done.

Hope this helps and apologies for the delay

1 Like

Okay, so I input the UUID in the player prefab, but now I am getting the same error at other random times. Here is the error:

image

It’s happening during the CaptureState method in the Fighter class.

public object CaptureState()
        {
            print(transform.name);
            return currentWeapon.name;
        }

I added the print statement to figure out which fighter class is being affected, in this case it is “Archer(1)”. So it’s not the player. The archer has something under current weapon, when the error is occurring, so I am not sure where the script is looking. I think this is still an UUID issue.

image

Last thing, the error doesn’t occur if I start in a scene with an enemy and go to another scene without an enemy. Then I seem to be able to go back and forth fine. Otherwise I get the error. All enemy classes have no UUID defined in prefab (i.e. it’s null).

Update on this problem. I added a debug to double check that the there was a “Current Weapon” during capture state. I discovered there was not. My only thought is that there is a race condition that capture state is being called fighter’s Start() function. I changed fighter’s Start() condition to Awake() and this seems to have solved the problem for the moment. Any more input would be welcome as I am not sure why this is happening.

Sounds like this is a race condition in our getcomponents being in start
I’ve gotten into the habit of always using awake over start now so we know the components are loaded when we try to get them.

Hope this helps

Im having the same issue yet haven’t yet found the solution. Iv changed my Start() to Awake() and still get the null error and I’m unable to save between scenes or saving manually on the spot. Iv double checked all my code to the lectures GitHub commit and see no differences. If I remove my code from this lecture the saving and loading is all good and working. Im having trouble isolating the location of this bug after this current lecture.

the weapon name does print() with the following below.

52

[Solution] In my scene I have wildlife (fish) , for some reason they had a fighter script attached to them with no default weapon (for obvious reasons) removed the fighter script and all is good.

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

Privacy & Terms