Forum rules - please read before posting.

SFX not remembering it is playing after loading save game.

Looping sound effects which have started playing before saving in-game, do not play when loading that save game. They have to be triggered again to play. Their gameObjects have both Sound (script) and Remember Sound (Script) components.

Any thoughts?

Thanks.

Comments

  • Try placing the AudioClip in question in a Resources folder, and giving it a unique filename.

  • edited July 2019

    Can you explain Resources Folder? The audio clip currently sits in Assets \ (game name) \ Audio

  • Create a folder inside (game name) named Resources, then move the clip into that. See the Manual's "Saving asset references" chapter for more on this topic.

  • ok thanks. So should all my audio live there, to avoid this problem?

  • It's more of a test at this point, to try to understand the issue. Did doing that cause the sound to play correctly upon loading?

  • Ok, I'll try it and get back to you.

  • Alright. I created the Resources folder then moved the sound clip there. Then updated Sound Game Object to point there. Same results as before, clip plays fine, but if I save then load my game the clip is not playing.

  • Let's see screenshots of the Sound object and the Action used to trigger it.

    Are you loading from within the same scene, or from another?

    What are your AC and Unity version numbers.

  • Unity 2018.3.6f1 Personal
    AC v1.66.7

    Everything is happening within one scene.

    So the Action is triggered and and the sound plays (looping) with the relative volume starting at 0, which is intentional. The volume is raised when getting closer to the room I want to hear the sound in. This all works and I don't think it's related to the sound not starting again when I Save and Load in that room, since I've tried starting the relative volume at 1 with no more success.

  • edited July 2019

    Recreated in both v1.66.7 and v1.68.4. This is an issue with Unity 2018, wherby a sound is considered as not playing at all if the game is paused. I shall look into a workaround.

    On the topic of "Relative volume", be aware that if you set the "Spatial Blend" to "3D", then it's volume will be based on the distance to the Audio Listener (typically on the MainCamera).

  • Try this - in Sound.cs, replace the "IsPlaying ()" function (around line 543) with the following:

    public bool IsPlaying ()
    {
        if (audioSource == null)
        {
            Initialise ();
        }
    
        if (audioSource != null)
        {
            if (KickStarter.stateHandler.IsPaused () && !playWhilePaused)
            {
                return (audioSource.time > 0f);
            }
    
            return audioSource.isPlaying;
        }
        return false;
    }
    
  • Fantastic work Chris. This appears to have fixed the issue! I will do more testing later, but for now this is solved. Am I right in understanding that this will be an issue for everyone now unless they insert that code?

  • In Unity 2018, yes, but this change will be made officially in the next AC update.

  • Got got a new bug related to this. The code worked and has been fine, but I think I've just come up against a bug when its a slightly different situation.

    At one point in my game there is a sfx looping and that sfx happens to be an Audio Source on a Sound gameobject which also contains multiple other Audio Source clips. When Saving then Loading, the clip looping changes to the first Audio Source clip on the gameObject instead of the one which was playing.

    I am guessing that the code remembers which GameObject was playing, but maybe not the specific clip?

  • Sorry - are you attaching multiple AudioSource components, or using a single AudioSource to play different clips?

    If you're changing which clip and AudioSource plays, you'll need to ensure that the reference to the clip is saveable. This essentially means giving it a unique filename, and placing it in a Resources asset folder - see the Manual's "Saving asset references" chapter for more.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.