Forum rules - please read before posting.

Player Starts No Longer Working

edited August 2021 in Technical Q&A

I just updated Unity to 2018.4.36 (from 2018.3) and now none of my Player Starts are working. Some things to note:

  • The default Player Starts work when you first begin the scene, but the Player Starts for entering from other scenes do not
  • The player is already in each scene - not spawned from a prefab
  • On the Player Start component, Previous Scenes are referenced by name, not number

This is using AC 1.73.8

Comments

  • Any related messages in the Console?

    I'll attempt a recreation, but it may be an issue with this particular version of Unity - I haven't heard or experienced such an issue in older or later releases.

  • Also, if you remember the "PM Teleport Test" script for teleporting Puppetmaster - I'm using that. Not sure if that makes a difference (unlikely, since the default player starts work).

    No relevant console messages.

  • edited September 2021

    It may well do - this isn't an issue I can recreate with AC itself.

    Do you have a copy of the script to share?

  • Try assigning the Demo game's Managers, and create a new test scene to switch to without involving PuppetMaster. Create a PlayerStart in it from the Demo's Basement scene, and test running a "Scene: Switch" Action to it from Basement (make sure that both scenes are in the Build Settings). Is the correct PlayerStart in the new scene recognised?

  • Sure, here's the script:

    using UnityEngine;
    using RootMotion.Dynamics;
    using AC;
    
    public class PMTeleportTest : MonoBehaviour
    {
    
        private Char character;
        public PuppetMaster puppetMaster;
    
        private void OnTeleport()
        {
            if (character == null) character = GetComponent<Char>();
            puppetMaster.Teleport(character.Transform.position, character.Transform.rotation, true);
            Debug.Log("Teleported PuppetMaster to " + character.Transform.position);
            character.Transform.localPosition = Vector3.zero;
        }
    }
    

    I'll try your suggestion and report back here. Really hope I can get this fixed, it's a real showstopper for me.

  • edited September 2021

    Okay, I tried with and without Puppetmaster and that (or maybe the script) is the cause.

    Starting in the test scene and switching to basement is no issue - basement starts at the correct player start. When going back to the test scene from the basement (in the same play session) is when it goes wrong - the player starts the test scene at the default player start instead of the desired "from scene" player start.

    So:
    Test Scene > Basement: Start location correct
    Basement > Test Scene: Start location uses default start instead of teleporting to correct spot

    When using character without PuppetMaster, there is seemingly no issue with start locations.

  • When going back to the test scene from the basement (in the same play session) is when it goes wrong - the player starts the test scene at the default player start instead of the desired "from scene" player start.

    To be clear: is this only when using your PuppetMaster character?

    What is the result when starting in the basement and going to the test scene for the first time, with the character that has the issue?

    I suspect the issue is that both AC and PM are controlling the character's position, creating a conflict.

    The above script will display a Console log whenever the character is teleported - this should include the moment the Player is placed at the PlayerStart. You're saying these messages are not displaying?

  • To be clear: is this only when using your PuppetMaster character?

    That's right - no issue without PuppetMaster.

    What is the result when starting in the basement and going to the test scene for the first time, with the character that has the issue?

    It is the same behaviour - go from Basement to Test scene for the first time and it will work correctly; character (and Puppet) will be teleported to the correct place when the new scene loads. But go back to the previous scene, and no Player Starts will be used - even default ones (I just found this out). The character will start at the place where they are originally positioned in the scene. Both scenes will now do this indefinitely until play is stopped.

    The above script will display a Console log whenever the character is teleported - this should include the moment the Player is placed at the PlayerStart. You're saying these messages are not displaying?

    Oh, they are displaying "Teleported PuppetMaster to (coordinates)", but there no new messages or warnings from AC. There are other debug messages from PuppetMaster, but they only appear as expected - when it "breaks" (when returning to the previous scene).

  • edited September 2021

    But go back to the previous scene, and no Player Starts will be used - even default ones (I just found this out).

    Do you have any Remember components attached to your Player objects?

    they are displaying "Teleported PuppetMaster to (coordinates)",

    Do these coordinates match up with the position of the intended PlayerStart? Start from Basement, clear the log, and then switch to Test scene - how many of these logs then appear, and what coordinates do they relate to? Share copies of the messages in full.

  • edited September 2021

    Do you have any Remember components attached to your Player objects?

    No, there are no Remember components on any player objects, but there are Constant IDs which I need for action list assets.

    Do these coordinates match up with the position of the intended PlayerStart?

    Yes, although they seem to be rounded up - possibly just to fit better in the console window? For example, my player start in the next scene is:
    X=0.5225787
    Y=4.775
    Z=-1.677787

    In the console it's just (0.5, 4.8, -1.7).

    Now when returning to the previous scene when teleporting doesn't work correctly, the teleport message is printed twice, so the player must be being teleported twice for some reason, even though it's not actually moved anywhere in the scene.

    Here is the first one:

    Teleported PuppetMaster to (2.9, 0.1, 5.0)
    UnityEngine.Debug:Log(Object)
    PMTeleportTest:OnTeleport() (at Assets/Game/PMTeleportTest.cs:15)
    UnityEngine.Component:SendMessage(String, SendMessageOptions)
    AC.Char:Teleport(Vector3, Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:1510)
    AC.Player:LoadData(PlayerData) (at Assets/AdventureCreator/Scripts/Character/Player.cs:787)
    AC.SaveSystem:AssignPlayerData(Player) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1582)
    AC.Player:set_ID(Int32) (at Assets/AdventureCreator/Scripts/Character/Player.cs:1227)
    AC.KickStarter:PreparePlayer() (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1199)
    AC.KickStarter:Initialise() (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1147)
    AC.MultiSceneChecker:Awake() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:43)

    Here is the second, I think it's mostly identical though:

    Teleported PuppetMaster to (-0.5, 4.8, -1.7)
    UnityEngine.Debug:Log(Object)
    PMTeleportTest:OnTeleport() (at Assets/Game/PMTeleportTest.cs:15)
    UnityEngine.Component:SendMessage(String, SendMessageOptions)
    AC.Char:Teleport(Vector3, Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:1510)
    AC.PlayerStart:PlacePlayerAt() (at Assets/AdventureCreator/Scripts/Navigation/PlayerStart.cs:74)
    AC.SceneSettings:AssignPlayerStart() (at Assets/AdventureCreator/Scripts/Game engine/SceneSettings.cs:127)
    AC.SceneSettings:OnStart() (at Assets/AdventureCreator/Scripts/Game engine/SceneSettings.cs:109)
    AC.SaveSystem:InitAfterLoad() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:691)
    AC.MultiSceneChecker:Start() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:62)

    So it teleports correctly on starting the first scene, teleports correctly again after changing to a second scene, but returning to previous scene is where it fails. Something must happen in a scene for it to somehow not be able to teleport the puppet on return, possibly something related to the player's position? I'm not sure, but if it works once, then that suggests there must be a way around it.

  • they seem to be rounded up - possibly just to fit better in the console window?

    Yes, vector3 values are rounded up when printed.

    the teleport message is printed twice, so the player must be being teleported twice for some reason

    This is the correct behaviour - first, the Player's saved data is loaded (including their position), and then they are teleported to the PlayerStart.

    So far as AC goes, the loading of saved data is the only difference between entering a scene for the first time vs re-entering it. Try temporarily commenting out line 787 of Player.cs, which is a Teleport function call. Does the issue remain?

  • I commented out that line but unfortunately the issue remains.
    Interestingly though, in the scene-return when it fails, only one teleport message is printed (now that line has been commented out), and the coordinates are actually correct - they are the same values of the Player Start that should be used, yet the player is in his starting position instead.

    btw I still have that "TeleportPM" script, if it helps, I can try using that in an OnStart cutscene instead of using player starts and see if it works better somehow?

  • edited September 2021

    Thanks for the details - you can un-comment the line again now.

    It sounds like AC is doing its job. Certainly give the TeleportPM script a try, but the issue may be to do with PuppetMaster not allowing for position changes, or the way the two assets are connected.

  • Damn, no luck with the script I'm afraid.

    I think what I'll do is, make a new project with just PuppetMaster and some way of changing scenes, then change scene, swap back again, and see if PuppetMaster gets messed up or not.

  • edited September 2021

    So, I tried an empty project just with PuppetMaster, and I was able to switch scenes back and forth forever without it breaking, so for whatever reason, it does not like returning to an AC scene.

    I thought of another idea though; what if at the start of each scene I used a different player that doesn't use PuppetMaster, then swap the player with the switch player action so that he's in the correct place without having to teleport?

    However, I cannot do this because the player component is not on the root object, it's on the character controller which is a child of the root object. AC won't accept a prefab in the player field (settings manager) that doesn't have the player component, even if it's on a child of that prefab.

    Is there a way around this please? Or maybe there's a way of having the player already in the scene but deactivated, then remove the spawned "dummy" player with a object remove action, not sure if that'd work though, or if it would still break the teleporting regardless.

  • Involving prefabs and player-switching makes the issue more complex: the most simple method of dealing with the Player is to have the character be in the scene file, as you are now.

    This isn't so much a bug with either AC or PuppetMaster, but the way in which they're working together. If it's not possible to put your Player component on the root, then you need a script that accounts for this when teleporting the Player.

    You should be contacting PuppetMaster's developer about this as well - he should have some ideas about this situation.

    Here's something to try, though: open up Char.cs and look for the Transform property near the bottom:

    public Transform Transform
    {
        get
        {
            if (_transform == null) _transform = transform;
            return _transform;
        }
    }
    

    Update it to:

    public Transform Transform
    {
        get
        {
            if (_transform == null) _transform = transform;
            return _transform;
        }
        set { _transform = value; }
    }
    

    Then, attach the following script to your Player:

    using UnityEngine;
    using AC;
    
    public class SetPlayerRoot : MonoBehaviour
    {
    
        private void Awake ()
        {
            GetComponent <Player>().Transform = gameObject.transform.parent;
        }
    
    }
    

    That will tell the Player to rely on their parent Transform instead of their own. I can't predict the results, but it's worth a try.

  • Cheers Chris, I'll give this a shot & also get in touch with Partel.

  • edited September 2021

    Good news: Partel (the developer of PuppetMaster) has created a new patch for PM that prevents the puppet from failing to initialize on start if the character is moved. I have the patch now and so far so good - you can return to scenes and the character will teleport to the correct PlayerStart.

    Not sure if I'm allowed to post the script here, but it will be included in the next update for PuppetMaster.

  • Great, thanks for the update.

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.