Hello, I’m a beginner making a simple project using unity 2018 with Visual Studio as an editor. I’ve only just set it up and I tried to call the DontDestroyOnLoad on a simple script inside the Start() function.
The call is written as follows:
public class CBattle : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
DontDestroyOnLoad.(gameObject);
SceneManager.sceneLoaded += OnSceneLoaded;
this.gameObject.SetActive(false);
}
…
Visual Studio throws a warning and doesn’t allow it to compile, even though I’ve seen another project use this method in this way. The warning text reads: “‘Object.DontDestroyOnLoad(Object)’ is a method, which is not valid in the given context”.
This is strange, since calling a method inside Awake, Start or Update is something I thought was normal.
Additionally, other errors I’m getting include certain references not being made automatic. If I call something in the Scene Manager, I have to include it in the script’s references.
Could this be related to the issue? I appreciate your help.