Following setup:
Here the master Volume is set:
public class GameController : MonoBehaviour
{
[Header("Audio")]
[SerializeField] float soundFXMasterVolume = 0.5f;
public float GetSoundFXMasterVolume()
{
return soundFXMasterVolume;
}
}
And here it is referenced and read:
public class ClipManager : MonoBehaviour
{
[SerializeField] GameObject positionedSoundPrefab = default;
[SerializeField] ClipDefinition[] clipDefinitions = default;
AudioSource audioSource = default;
GameController gameController = default;
float soundFXMasterVolume = 1f;
SpawnedObjectsController spawnedObjectsController = default;
Transform instanceParent = default;
private void Awake()
{
audioSource = GetComponent<AudioSource>();
gameController = FindObjectOfType<GameController>();
spawnedObjectsController = FindObjectOfType<SpawnedObjectsController>();
}
private void Start()
{
soundFXMasterVolume = gameController.GetSoundFXMasterVolume();
instanceParent = spawnedObjectsController.sound;
}
}
But unfortunately for one of several prefab types that is not working.
The soundFXMasterVolume for that one prefab is not correctly returned. It seems I always get the very first value I set for the serialized field.
To fix it, I have to move the line
soundFXMasterVolume = gameController.GetSoundFXMasterVolume();
from the Start() method to Awake() - which from my understanding is not the correct way to do it.
The prefab that generates the problem is calling the clip manager in its Start() method, which all the others don’t.
What could it be that I am missing to see?
Thanks for the help