Accessing a string from a different scene

So I have the following problem:
I have two scenes, a main menu scene and a test scene.
In the main menu scene I have a script that’s attached to a GameObject (a button) and it writes a string for a file path that’s written to the game folder.
In the test scene at some point I want to access that string and do things with it. However I am having a lot of trouble referencing the GameObject and its script because the parent Canvas is not active. Is there a command or method I can use to access information under inactive GameObjects in different scenes?

Thank you

Are both scenes loaded at the same time or are you switching between scenes. Because if you are switching between them then everything is destroyed unless you specifically tell the object to not be destroyed on load. But anyway for that situation, where you want to preserve information between scenes I’d just use a scriptable object.

Also the docs on it

if its simple one string, can also use playerprefs (save to PlayerPrefs in main scene, then load in test scene)

Both scenes are loaded at the same time, the only thing that happens that the main menu objects under a canvas tree are deactivated before controlling the main test scene.
And as far as using a scriptable object is concerned. Is there a way for a script/GameObject to write TO a scriptable object and not the other way around? Because I have two input fields connected via a script that adds all the strings together, creates a .csv file and outputs a file path. I want that file path to survive between scenes to be used later in the other scene.

Well as mgear suggested if it is just a string you can use PlayerPrefs and that information would persist even when you restart the game. So I’d go with this solution in your case.

As for writing to a scriptable object, you create a new one in your project, have your script reference it, and then you can access it like you would any other class. But just keep in mind in a deployed build once you restart the app/game the scriptable objects data will be reset to what it was when the build was launched.

“When you use the Editor, you can save data to ScriptableObjects while editing and at run time because ScriptableObjects use the Editor namespace and Editor scripting. In a deployed build, however, you can’t use ScriptableObjects to save data, but you can use the saved data from the ScriptableObject Assets that you set up during development.”

Not to double post but I might have side stepped the original problem. If you are deactivating your objects and then using something like GameObject.Find then it won’t work.

“This function only returns active GameObjects. If no GameObject with name can be found, null is returned”

So if you get a reference to the object before you deactivate it, the information should still be there. If you destroyed the GameObject then the data would be lost.

Doc: