Unity Object created by script is only updated after i selected it on the play mode editor

So, when i created an object with a script, the object only updates after i select on the play mode editor when it should automatically get initialized, here is the video showing the issue. i don’t know how it will affect the built app but i haven’t tested it yet on a device because i can’t really use AR on my device, still waiting for my friend to wake up hours later

z81tf3

and here’s the code, at CreateScatterplotVisualization method

using System.Collections;
using System.Collections.Generic;
using IATK;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class ConfigListener : MonoBehaviour
{
    public TMP_Dropdown dropdownX;
    public TMP_Dropdown dropdownY;
    public TMP_Dropdown dropdownZ;

    // Start is called before the first frame update
    void Start()
    {
        string csvPath = PlayerPrefs.GetString("FilePath");
        CSVDataSource dataSource = new CSVDataSource();
        dataSource.LoadFromFile(csvPath);

        // Get the available dimensions
        List<string> dimensions = new List<string>();
        for (int i = 0; i < dataSource.DimensionCount; i++)
        {
            dimensions.Add(dataSource[i].Identifier);
        }

        // Populate the dropdown menus
        dropdownX.ClearOptions();
        dropdownX.AddOptions(dimensions);

        dropdownY.ClearOptions();
        dropdownY.AddOptions(dimensions);

        dropdownZ.ClearOptions();
        dropdownZ.AddOptions(dimensions);
    }

    // to load the next scene
    public void LoadAR()
    {
        SceneManager.LoadScene("datavisual", LoadSceneMode.Single);
        SceneManager.sceneLoaded += OnSceneLoaded;
    }

    private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {

        string xDimension = dropdownX.options[dropdownX.value].text;
        string yDimension = dropdownY.options[dropdownY.value].text;
        string zDimension = dropdownZ.options[dropdownZ.value].text;
        if (scene.name == "datavisual")
        {
            CreateScatterplotVisualization(xDimension, yDimension, zDimension);
            SceneManager.sceneLoaded -= OnSceneLoaded; // Unsubscribe from the event
        }
    }

    private void CreateScatterplotVisualization(string xDimension, string yDimension, string zDimension)
    {
        // Find the Ground Plane Stage GameObject in the datavisual scene
        GameObject groundPlaneStage = GameObject.Find("Ground Plane Stage");

        if (groundPlaneStage != null)
        {
            // Create a new GameObject for the visualization
            GameObject visualizationObject = new GameObject("ScatterplotVisualization");
            visualizationObject.transform.SetParent(groundPlaneStage.transform);

            // Add the Visualisation component to the new GameObject
            Visualisation visualisation = visualizationObject.AddComponent<Visualisation>();
            string csvPath = PlayerPrefs.GetString("FilePath");
            CSVDataSource dataSource = visualizationObject.AddComponent<CSVDataSource>();
            dataSource.LoadFromFile(csvPath);

            // Configure the Visualisation component
            // visualisation.visualisationType = AbstractVisualisation.VisualisationTypes.SCATTERPLOT;

            visualisation.dataSource = dataSource;
            visualisation.xDimension.Attribute = xDimension;
            visualisation.yDimension.Attribute = yDimension;
            visualisation.zDimension.Attribute = zDimension;
            visualisation.geometry = AbstractVisualisation.GeometryType.Points;
            visualisation.updateProperties();
           
            visualisation.CreateVisualisation(AbstractVisualisation.VisualisationTypes.SCATTERPLOT);


        }
        else
        {
            Debug.LogError("Ground Plane Stage GameObject not found in the datavisual scene.");
        }
    }

    // Update is called once per frame
    void Update()
    {

    }
}

I feel like this method is the culprit. The LoadScene method is a blocking method meaning it will stop all execution on the main thread until it has completed the load, and since the load will have already completed it’s not correctly triggering sceneLoaded. Try reversing the order of these two lines.

public void LoadAR()
{
    SceneManager.LoadScene("datavisual", LoadSceneMode.Single);
    SceneManager.sceneLoaded += OnSceneLoaded;
}

nope, still the same behavior :confused:

Well, show your “Visualisation” script. That’s the one responsible and you only showed where you created it. Keep in mind that serialized variables are not automatically initialized when you create an instance through AddComponent unless you actually have a field initializer on that serialized field. However when you select an object in the editor, serializable fields would be initialized by the inspector. So you probably missing some initialization in your Visualisation or CSVDataSource script. We don’t know what they actually do so we can’t really tell you anything about how to solve your issue. All we can say is that the shown code is probably irrelevant for the issues with those other scripts.

you can check it on this repo

https://github.com/MaximeCordeil/IATK

on Assets/IATK/Scripts/Controller