Forum rules - please read before posting.

How to save first person camera transform properly?

edited February 24 in Technical Q&A

I have a first-person player character using the FP player from the Downloads. The player has an item held in their right hand (through Character > Hold Object action) with a Remember Scene Item and Remember Transform component attached. When I save my game and reload, the held item sometimes does not appear at local (0,0,0), depending on the rotational X-axis value (up and down) of the FP camera. It seems that when the scene loads from a save file, the camera is always reset back to (0,0,0), and since my player is holding an object on their hand with a remember component attached, the position in which the item shows up is offset or something.

So, how can I, upon loading a save file, restore the rotation values of the camera at the time of the save?

Comments

  • Welcome to the community, @imakeinternet.

    Is this a case of the hand attachment point being a child of the first-person camera?

    If so, I can see this happening - as you rightly point out that the camera's pitch is not saved.

    I will see about addressing this as part of AC's next update - thanks for the report and use-case.

    In the meantime, you should be able to work around it with a temporary script (i.e. until the update) that resets the pitch at the moment the game is saved/loaded. Try this, which uses AC's event system, attached to your First Person Camera:

    using UnityEngine;
    using AC;
    
    public class ResetCameraPitch : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnBeforeSaving += OnBeforeSaving;
            EventManager.OnBeforeLoading += OnBeforeLoading;
        }
    
        private void OnDisable ()
        {
            EventManager.OnBeforeSaving -= OnBeforeSaving;
            EventManager.OnBeforeLoading -= OnBeforeLoading;
        }
    
        private void OnBeforeSaving (int saveID)
        {
            GetComponent<FirstPersonCamera> ().SetPitch (0f);
        }
    
        private void OnBeforeLoading (int saveID)
        {
            GetComponent<FirstPersonCamera> ().SetPitch (0f);
        }
    
    }
    
  • Excellent workaround Chris. For now, I simply moved the right and left hands outside the camera and directly as children of the player object. This works for now. You are correct in that the case is that of the hands being children of the FP camera.

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.