How can I communicate with the ImageInfoPrefab from my scene?
Hi All,
I am a masterstudent Interaction Designer and working with Unity AR Foundations for my thesis. I am relatively new to Unity but used other games engines like Unreal Engine before. So sorry if this is a noob question, but haven't found a solution yet for the last week.
So I am experimenting in my thesis with Physical Computing & AR. Via the Uduino plugin I connected Unity with my Arduino through WIFI. The Uduino component and script have to be in the ImageTracking Scene. But I want stuff to happen in my ImageInfoPrefab based on the input I get from my Arduino. I tried everything but my scene-script and Prefabscript would not communicate with each other.
The problem that I found is that because the ImageInfoPrefab isn't in the scene at start (but is initiated trough the AR Tracked Image Manager Script) both scripts cannot communicate with each other. And I don't know the solution for that.
The code down below is a script that is in my scene. In this script all the data from my Arduino is read and pushed to Unity. In the following example a boolean goes to true if data = 0 and it works.
public Text textZone;
public Boolean spelStart = false;
public static Boolean triggerBoolean = false;
// Start is called before the first frame update
void Start()
{
UduinoManager.Instance.OnDataReceived += DataReceived;
UduinoManager.Instance.alwaysRead = true; // This value should be On By Default
UduinoManager.Instance.pinMode(1, PinMode.Input);
}
void DataReceived(string data, UduinoDevice board)
{
Debug.Log(data);
textZone.text = data;
// So if the data from my Arduino says 0 the following boolean needs to be true
if (data == "0")
{
Debug.Log("Spelinteractie 1 begint");
spelStart = true;
}
}
void Update() {
}
} `
The code below is from my ImageInfoPrefab. When the boolean = true something needs to happen. But not is happening even the debug.log isn't printing.
public MeshRenderer Vingerafdruk1;
public MeshRenderer Vingerafdruk2;
// Start is called before the first frame update
void Start()
{
//Vingerafdruk
Vingerafdruk1.gameObject.SetActive(false);
Vingerafdruk1.enabled = false;
Vingerafdruk2.gameObject.SetActive(false);
Vingerafdruk2.enabled = false;
}
// Update is called once per frame
void Update()
{
if (spelStart == true) {
Debug.Log("Spelstart is nu op true");
Vingerafdruk1.gameObject.SetActive(true);
Vingerafdruk1.enabled = true;
}
}
}
I dropped some screenshots down below.
Thx a lot in advance.


Hi,
Could someone help me please. Am still stuck :/
How can I efficiently let the ImageTracking Scene communicate with the ImageInfoPrefab.
Tyvm.
So basically to send information in to the prefab you need to use GameObject.GetComponent
So assuming the script in your prefab is called "PrefabScript" then you would use in the scene code `private GameObject ImageInfoPrefab bool spellStart = true;
ImageInfoPrefab = _trackImageManager.trackedImagePrefab;
ImageInfoPrefab.GetComponent
and in the Prefab script have a method
`private bool SpellStart;
public void SetSpellStart(bool IsStarting) { SpellStart = IsStarting; }`
There may be a way to set the variable more directly - I am still somewhat new to Unity as well as well but this worked for me.
Tyvm @jiungerich for your help. Appreciate it very much.
But I get some errors if I do what you told me to do. I'm still very new in Unity, so I hope you bare with me and would check the code / errors below if you see something that I did wrong.
Tyvm
ERRORS
Severity Code Description Project File Line Suppression State
Error CS0103 The name '_ARtrackImageManager' does not exist in the current context
Severity Code Description Project File Line Suppression State
Error CS0411 The type arguments for method 'GameObject.GetComponent
SCENE SCRIPT
public class ReadKeypad : MonoBehaviour
{
public Text textZone;
private GameObject ImageInfoPrefab;
bool spellStart = true;
// Start is called before the first frame update
void Start()
{
UduinoManager.Instance.OnDataReceived += DataReceived;
UduinoManager.Instance.alwaysRead = true; // This value should be On By Default
UduinoManager.Instance.pinMode(1, PinMode.Input);
ImageInfoPrefab = _ARtrackImageManager.trackedImagePrefab;
ImageInfoPrefab.GetComponent().SetSpellStart(spellStart);
//should it be this?
ImageInfoPrefab = ARTrackedImageManager.trackedImagePrefab;
}
void DataReceived(string data, UduinoDevice board)
{
UnityEngine.Debug.Log(data);
textZone.text = data;
if (data == "2")
{
UnityEngine.Debug.Log("Spelinteractie 1 begint");
}
}
void Update() {
}
} ` PREFAB SCRIPT
public class kepadTriggers : MonoBehaviour
{
private bool SpellStart;
// Start is called before the first frame update
void Start()
{
}
void Update()
{
}
public void SetSpellStart(bool isStarting)
{
SpellStart = isStarting;
}
}
Having an issue actually posting full code because github edits out necessary carets needed in the code. S
You need to pull the ARtrackedImageManager into your script - that is why you are having the error.
The debug log is telling you the AR tracked image manager is missing.
The monobehaivor code that you are writing should be attached to AR session origin with the ArTrackedImageManager as a component. Then include:
It is also possible to instantiate AR tracked image manager in script but I have had issues in doing so on android devices.
*Editted because code was not showing properly
@SirLouLou
Just wondering if jiungerich's solution has solved the issue? If not, let me know if you are still getting the errors mentioned your post above.