- Home /
Change SetActive(true/false) from a GameObject which is child of a different ImageTarget
Hi there,
I have two Vuforia ImageTargets. One has a keyboard as a child. There is a c# script attached to the keyboard which checks if I type in the correct pin.
The other ImageTarget has two GameObjects as children. One is activated and the other one deactivated by default (SetActive(true/false).
My question is, how can access the SetActive() of these children from the script which is attached to the keyboard in the first ImageTarget? I want one GameObject two disappear and the other one to appear if I type in the correct Pin.
I already tried a lot with GetComponent to call a method in a second script attached two the second ImageTarget. But it always gives me errors about nullreferenceobject.
Do you guys have any kind of tipps or simple methods to solve this situation?
Thanks in advance!
Answer by unity_BUJQdslYm7EuFQ · Jul 16, 2021 at 04:32 AM
An error NullReferenceException occurs when you are trying to do smth with a variable which equals null. To solve the problem add a public or [SerializeField] when you announcing a variable like:
[SerializeField] GameObject gameObject; //it`s better
//or
public GameObject gameObject;
Then, you should drag the gameObject in fitted field in inspector.
If I answered incorrect, please explain me my mistake.
Thank you so much! Dragging the gameObject in the fitted field in the inspector was the missing thing here! :)
Your answer
Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Why is this null? Finding a script on an object 3 Answers
Object reference not set to an instance of an object in c#. 0 Answers
Assign collider and linerenderer to list 1 Answer
NullReferenceException - Editor script using GetComponent after AddComponent 1 Answer