Need Help with Karting Microgame Tutorial

Could you post the code for every file you’ve soft deleted? It looks like there’s a missing character somewhere (a semi-colon or a bracket) but without the code it’s hard to tell.

nice thank you very much i am so stupid forgot the //

Wouldn’t it be easier to share a project without the default sounds? Many beginners have trouble modifying the code.

1 Like

We are not permitted to host and share example projects created by Unity. They are updated fairly frequently on the Unity Store so it’s good to make sure to get the latest version.

Hi,

I’m currently stuck on deleting the ‘Play Sound’ calls. I get varying messages when I do so. I have currently soft deleted what I believe I need to soft delete, Here’s a link to how my code looks. The first soft delete // is on line 87. I have attached a screenshot of the error messages as well. Thanks!

You have commented out void PlaySound(AudioClip sound) which is the function created. You need to comment out/delete the calls to this function (basically every other instance of PlaySound( aside from this one).

thanks, this was very helpful!

Hello! I feel very close to completing this, but am stuck on the following error:

UnassignedReferenceException: The variable Drift of ArcadeEngineAudio has not been assigned.
You probably need to assign the Drift variable of the ArcadeEngineAudio script in the inspector.
KartGame.KartSystems.ArcadeEngineAudio.Update () (at Assets/Karting/Scripts/KartSystems/KartAudio/ArcadeEngineAudio.cs:43)

This error is posted repeatedly (like several times a second) while the game is playing, in case that tells you something useful.

I did re-read the instructions and it seems I’ve followed everything, but obviously I can’t find my error. Please help! Thank you!

Here’s a screenshot of the error in case it provides better info

And here’s the script that I believe the error is referring to (Assets/Karting/Scripts/KartSystems/KartAudio/ArcadeEngineAudio). Searching “drift” results in 4 hits… but I don’t know what I should be doing.

using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;

namespace KartGame.KartSystems
{
    /// <summary>
    /// This class produces audio for various states of the vehicle's movement.
    /// </summary>
    public class ArcadeEngineAudio : MonoBehaviour
    {
        [Tooltip("What audio clip should play when the kart starts?")]
        public AudioSource StartSound;
        [Tooltip("What audio clip should play when the kart does nothing?")]
        public AudioSource IdleSound;
        [Tooltip("What audio clip should play when the kart moves around?")]
        public AudioSource RunningSound;
        [Tooltip("What audio clip should play when the kart is drifting")]
        public AudioSource Drift;
        [Tooltip("Maximum Volume the running sound will be at full speed")]
        [Range(0.1f, 1.0f)]public float RunningSoundMaxVolume = 1.0f;
        [Tooltip("Maximum Pitch the running sound will be at full speed")]
        [Range(0.1f, 2.0f)] public float RunningSoundMaxPitch = 1.0f;
        [Tooltip("What audio clip should play when the kart moves in Reverse?")]
        public AudioSource ReverseSound;
        [Tooltip("Maximum Volume the Reverse sound will be at full Reverse speed")]
        [Range(0.1f, 1.0f)] public float ReverseSoundMaxVolume = 0.5f;
        [Tooltip("Maximum Pitch the Reverse sound will be at full Reverse speed")]
        [Range(0.1f, 2.0f)] public float ReverseSoundMaxPitch = 0.6f;

        ArcadeKart arcadeKart;

        void Awake()
        {
            arcadeKart = GetComponentInParent<ArcadeKart>();
        }

        void Update()
        {
            float kartSpeed = 0.0f;
            if (arcadeKart != null)
            {
                kartSpeed = arcadeKart.LocalSpeed();
                Drift.volume = arcadeKart.IsDrifting && arcadeKart.GroundPercent > 0.0f ? arcadeKart.Rigidbody.velocity.magnitude / arcadeKart.GetMaxSpeed() : 0.0f;
            }

            IdleSound.volume    = Mathf.Lerp(0.6f, 0.0f, kartSpeed * 4);

            if (kartSpeed < 0.0f)
            {
                // In reverse
                RunningSound.volume = 0.0f;
                ReverseSound.volume = Mathf.Lerp(0.1f, ReverseSoundMaxVolume, -kartSpeed * 1.2f);
                ReverseSound.pitch = Mathf.Lerp(0.1f, ReverseSoundMaxPitch, -kartSpeed + (Mathf.Sin(Time.time) * .1f));
            }
            else
            {
                // Moving forward
                ReverseSound.volume = 0.0f;
                RunningSound.volume = Mathf.Lerp(0.1f, RunningSoundMaxVolume, kartSpeed * 1.2f);
                RunningSound.pitch = Mathf.Lerp(0.3f, RunningSoundMaxPitch, kartSpeed + (Mathf.Sin(Time.time) * .1f));
            }

            
        }
    }
}

Hi,

Typically, this specific error message indicates that you’re trying to do something to a variable but haven’t assigned it to anything. You can see that the declaration public AudioSource Drift; isn’t actually assigning anything (i.e. public AudioSource Drift = something;) and it isn’t being assigned later in the script either. As the error message notes, Unity may be expecting you to assign Drift by dragging an AudioSource component into the Drift field in the inspector. This code is all related to Unity’s audio system, and the references to each AudioSource (e.g. Drift) should be set up by in the tutorial project by default.

However, since you’re replacing Unity’s audio with FMOD Studio here, they’re probably broken since you’ve done something to those AudioSource components, or the GameObjects that contain those AudioSources. This leads me to think you may have missed step 16 of the Adding Sounds: Kart Engine part of the tutorial, which involves replacing the code in the ArcadeEngineAudio script with the following code that handles the audio with FMOD:

using UnityEngine;

namespace KartGame.KartSystems
{
    /// <summary>
    /// This class produces audio for various states of the vehicle's movement.
    /// </summary>
    public class ArcadeEngineAudio : MonoBehaviour
    {
        public float minRPM = 0;
        public float maxRPM = 5000;
        ArcadeKart arcadeKart;

        void Awake()
        {
            arcadeKart = GetComponentInParent<ArcadeKart>();
        }

        void Update()
        {
            float kartSpeed     = arcadeKart != null ? arcadeKart.LocalSpeed() : 0;
            // set RPM value for the FMOD event
            float effectiveRPM = Mathf.Lerp(minRPM, maxRPM, kartSpeed);
            var emitter = GetComponent<FMODUnity.StudioEventEmitter>();
            emitter.SetParameter("RPM", effectiveRPM);
        }
    }
}

This should remove the variables and code that is throwing errors.

Hope this helps!