Forum rules - please read before posting.

Issue after upgrading to 1.85.1 Kickstarter.player is null

Hiya. We've been working on this project for a year or so and as we are wrapping things up we had to upgrade unity version due to the unity security issue bug. That means we had to upgrade AC as well. We were using 1.72.4 and now we moved to 1.85.1 version and a number of issues has popped up that have broken our game. A big number of the issues is due to the fact that kickstarter.player returns null when it's run in a start function of a script. Even when I'm already playing the game, so my character has loaded, when I switch a scene, if that scene has scripts that try to access kickstarter.player, it returns null which breaks the game. What is the correct way to access the player now?

Comments

  • edited November 7

    Welcome to the community, @fruitpunchsamuraigr.

    Are you using Player-switching, a local Player in the scene, and/or the use of Addressables to spawn them? These will all affect exactly when the Player variable is set and available to use.

    It might be enough for your script to simply have a positive Execution Order for it to be called after AC's initialisation process, but the most reliable way to ensure Player references is to hook into the OnPlayerSwitch event in OnEnable if the value is currently null, i.e.:

    void Start()
    {
        if (KickStarter.player)
        {
            OnSetPlayer(KickStarter.player);
        }
        else
        {
            EventManager.OnSetPlayer += OnSetPlayer;
        }
    }
    
    void OnDestroy()
    {
        EventManager.OnSetPlayer -= OnSetPlayer;
    }
    
    void OnSetPlayer(Player player)
    {
        //
    }
    
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.