I have a scene with the following hierarchy:

enter image description here

This is game scene and the game manager is a singleton with the following variable fields:

// canvas
public Canvas PauseCanvas;
public Canvas MainMenuCanvas;

Before implementing singleton, I assigned them from the inspector. Now that the game manager is singleton, I need to assign them through script on level load. I can see one solution to this situation:

  • Getting all canvas components through GetComponents<Canvas>() and then iterating and checking their name fields to assign them accordingly or maybe using LINQ.

What I want to ask is: Is there a name-based search method just like finding game objects with name GameObject.Find("Name") that is applicable for Components?


There is no such method but you can use this to find your elements : yourCanvas = GameObject.Find("CanvasName").GetComponent<Canvas>();

| improve this answer | |
  • \$\begingroup\$ The main problem was choosing canvasses from multiple canvas components of a game object according to canvas' name. I used LINQ to solve it tho. Still, thanks for the answer. \$\endgroup\$ – Varaquilex Jan 14 '15 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.