Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
If and ActiveSelf. Only works once. With example project

First time developer here and I am struggling with a problem. I made a mock up of the problem in regular Unity 3d since the VR scares some talented people away from helping me. That can be downloaded here: https://gofile.io/d/qHDlUZ File is a zip called: SoundTestTroubleShooting. A Unity build on 24.7MB Follow the number on the buttons. Button 1 "Choose Music" Activates the Cube. Button 2/4 "Play Music" Checks if cube is activated and plays song if that is the case. Button 3 "Restart Scene" Stops the music and reloads the scene. Cube has dontdestroyonload. After that i press button 2/4"PlayMusic" and it cant find that the cube is active. WHY?! Going nuts here.

Old text with the entire problem here:

In my game I have four songs in the start menu that my player gets to choose from. He chooses one by pressing one of four buttons. This activates an empty GameObject, lets call it SmileMusicTrigger. SmileMusicTrigger has a dontdestroyonload and is deactivated by the other three buttons if player wants to switch song.

Player press Begin which moves him into position. He presses start and this button has:

 public GameObject SmileMusicTrigger;
public GameObject EpicMusicTrigger;
public GameObject GodMusicTrigger;
public GameObject VikingMusicTrigger;

void OnTriggerEnter()
   {
    if (SmileMusicTrigger.activeSelf)
    {
        AudioManager.instance.Play("Smile");
    }
    if (EpicMusicTrigger.activeSelf)
    {
        AudioManager.instance.Play("Epic");
    }
    if (GodMusicTrigger.activeSelf)
    {
        AudioManager.instance.Play("God");
    }
    if (VikingMusicTrigger.activeSelf)
    {
        AudioManager.instance.Play("Viking");

and my game start and and the music begins fine. When player dies he restarts the scene with restart button which has this to say about the music:

   void OnTriggerEnter()
{
    AudioManager.instance.Stop("Smile");
    AudioManager.instance.Stop("Viking");
    AudioManager.instance.Stop("God");
    AudioManager.instance.Stop("Epic");

} }

after this code has run the scene restarts and it does not seem like my Start button can check the active state of SmileMusicTrigger again. I know SmileMusicTrigger is active through the restart of the scene because I see it under dontdestroy in the hierarchy when game is running and it is checked as on in inspector. But I cant seem to call it again. Thus my music only plays once.

Audiomanager is also under Donotdestroy so I dont think the problem is there.

Sorry if this is messy. I am working really hard to get this working but I am so stuck right now. Thankful for any help. All the best!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!