Spawn a prefab from another prefab

I’m new to Unity. I have an invisible GameObject , call it A, with only a script, that instantiates a prefab B multiple times.
I need spawned clones of B to have reference back to A, I have learned that in order for this to work, A has to be a prefab itself (correct me if I’m wrong)
Spawned B objects react to mouse clicks and call a method of A.
The problem is that inside this called method of A, the variables of A itself have values that I don’t expect, for example a certain variable that was initialized to 0 in Start() and never used has a value of 12.
It seems like every spawned object B has a reference to its “own” A, and variables of A have random values.
What am I missing?

in the empty game object’s script that does the spawning assuming there is only one, You can simply mark variables or functions in the spawning script as static variables. when marked as static, any script in the scene shares it and can access it.

in the newly spawned objects if there are scripts attached, spawning will create new and independent instances of the scripts and variables in those scripts. if the initial script needs references to what it has spawned. then the first script need to store references to them as it spawns…probobly in an array or something similar

if you are having problems with code acting unexpectedly, please post it so we can help