Audio somehow seems to be messing with my thrust or performance

Adding the audio component seems to have had a pretty adverse effect on my game.
Easier to show than explain I think With Audio and Without audio

I think it must be performance related as stats seem to show roughly 80fps when I have no audio component. When I attach one though the first play seems normal, yet every time I replay it the thrust seems to get lower and lower and my fps absolutely tanks. My google Fu seems to be failing me with this as it appears to be a problem others have had but all responses/solutions are very outdated or completely beyond my scope of understanding.

I’m going to continue having a mess around with it, re-watch the videos again in case there is some checkbox somewhere I haven’t clicked but I don’t understand why this is happening, it feels like a memory leak in a game but amplified to the extreme.

A couple of things you could try as a test;

  • Leave the AudioSource attached as a component, but disable (un-tick it) and run the game
  • Change the audio clip, perhaps record something very short yourself and run the game

Any noticeable changes?

Hey Rob have been fiddling around a little, I added the Time.DeltaTime https://prnt.sc/io6csvthat Ben mentions in a previous video to see if it was related to frame rate and it appears to work fine once I adjusted the mass. (excuse the position of the else statement i fixed that)

The audio file I used is not that big (less than 5 mb) is it normal for unity editor to struggle that much with something so small? It seems to be working at the moment so i’m going to continue and hope with a bit more understanding latter down the line I will have worked out what I did wrong.

Cheers for the speedy reply.

1 Like

Hi,

Regarding your query about audio size, not really, but you would want to minimise where-ever you can. I was merely trying to rule out items as you progressed through your debugging.

I can’t see your code in the link, presumably a screenshot? It says it’s been removed.

Sounds to me as if you have resolved the issue through the use of the Time.deltaTime.

For reference you can copy/paste your code directly into your posts, also, you can embed your YouTube videos by just pasting the URL, some further info below :slight_smile:


See also;

Hmm not sure why it’s vanished

if (Input.GetKey(KeyCode.Space))
        {
            rigidBody.AddRelativeForce(Vector3.up * Time.deltaTime);
            if (!audio.isPlaying)
            {
                audio.Play();
            }                 
        } else
            {
                audio.Stop();
            }     

I can’t see it causing any problems and it appears to have fixed my issue for the moment It’s just bugging me that i’m missing something at the moment. Going to move on though and fingers crossed it doesn’t bite me later.

Thanks for the help though

1 Like

You tend to not use Time.deltaTime when you are applying forces to Rigidbodies in Unity - however - because you are checking for the input in the Update method, which is frame dependent you need to apply this to take into account the time between frames.

Ty Rob between here and the help i’ve gotten on discord I have a functional if slightly different to Ben’s project, but it works which I suppose is the main point :sweat_smile:

1 Like

If you want to get it to be the same, easily, you can grab the code from GitHub.

Although, from what I can tell from where you are at the moment, it changes significantly in a bit anyway :slight_smile:


See also;

Privacy & Terms