Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Saving of multiple Vector2 scriptableObjects

Discussion in 'Editor & General Support' started by akyholicx, Sep 3, 2021.

  1. akyholicx

    akyholicx

    Joined:
    Oct 17, 2018
    Posts:
    1
    I am currently having issues with my function which saves 3 vector2's into 3 unique scriptableObjects each.
    When I build the project, either only one of the vector2 gets saved or 2 of vector2. When I swab the position around in code, it would produce another combination but never saves all 3 vector2.

    Code (CSharp):
    1. // For Camera Min, Max Position
    2.     public Vector2 cameraMaxPosition;
    3.     public Vector2 cameraMinPosition;
    4.     public VectorValue camMaxPos;
    5.     public VectorValue camMinPos;
    6.  
    7.     // For player position
    8.     public GameObject playerPosition;
    9.     public Vector2 playerPositionVector;
    10.     public VectorValue playerStorage;
    11.  
    12. public void battle()
    13.     {
    14.         // Function for when enemy is hit
    15. [B]        // Remember player's current position
    16.         playerPositionVector = (Vector2)playerPosition.transform.position;
    17.         playerStorage.initialValue = playerPositionVector;
    18.  
    19.         // Save cam max pos
    20.         camMaxPos.initialValue = cameraMaxPosition;
    21.         camMinPos.initialValue = cameraMinPosition;[/B]
    22.  
    23.         // Pass enemystats to savedStats for use in battle scene
    24.         savedStats.initialValue = enemystats;
    25.  
    26.         // Pass GameObject value
    27.         isDeadStorage.enemyName = currentEnemyGameObject.name;
    28.         isDeadStorage.isDead = currentEnemyGameObject.GetComponent<Enemy>().isDead;
    29.  
    30.         StartCoroutine(FadeCo());
    31.      }
    32.  
    33.     public IEnumerator FadeCo()
    34.     {
    35.  
    36.         if (fadeOutPanel != null)
    37.         {
    38.             Instantiate(fadeOutPanel, Vector3.zero, Quaternion.identity);
    39.         }
    40.         yield return new WaitForSeconds(fadeWait);
    41.  
    42.  
    43.         AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneToLoad);
    44.         while (!asyncOperation.isDone)
    45.         {
    46.             yield return null;
    47.         }
    48.     }
    49.  
    50.  
    51.     }
    Code (CSharp):
    1. [CreateAssetMenu]
    2. public class VectorValue : ScriptableObject, ISerializationCallbackReceiver
    3. {
    4.     public Vector2 initialValue;
    5.     public Vector2 defaultValue; //2.22, -1 (max), 1.77, -3(min)
    6.  
    7.     public void OnAfterDeserialize()
    8.     {
    9.         initialValue = defaultValue;
    10.     }
    11.  
    12.     public void OnBeforeSerialize()
    13.     {
    14.     }  
    15. }


    The part i am having issue is bolded. I am unsure if this is an inherent Unity limitation whereby it is unable to save 3 Vector2 into scriptableObjects at one go or something else.