Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Al_Capwn · Feb 13, 2017 at 12:10 PM · guiprefabinstantiation

How to access a GUI element in an instantiated prefab?

Hi,

I have created a Prefab which contains a slider, for example sliderResonance. Now, when I instantiate the Prefab from code, I cannot find a way to access each individual sliderResonance and set its value from code.

You can think of this application as collection of softsynths; I want to create several identical "musical instruments", each which can play their own sounds. The user shall be able to load many of these, thats why I instantiate them from code.

Now, another part of the application, the sequencer, needs to be able to access and modify any of these sliders individually.

Example code:

 public class TB1 : MonoBehaviour {
 
     public Transform Synth1;          // This is the Prefab, which works as expected when alone    
 
     void Start()
     {
         Instantiate(Synth1, canvas[canvasApp].transform, false);
         Synth1.transform.localScale = new Vector3(1, 1, 1);
         Synth1.transform.localPosition = new Vector3(0, -334, 0);
 
         Instantiate(Synth1, canvas[canvasApp].transform, false);
         Synth1.transform.localScale = new Vector3(1, 1, 1);
         Synth1.transform.localPosition = new Vector3(0, -1000, 0);
     }
 
 }

Now the above seems to work fine; the Prefabs are loaded into the game, and they work as expected. BUT when I try to access the sliders, see code below, only one (random) gets accessed, I guess it is because they have the exact same name, since they are instances of the same Prefab:

    Slider test1 = Synth1.Find("sliderResonance");
    test1.value = 50;


How on Earth do I access a specific one??? Sorry for being quite new at this; all help is appreciated.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Strange GUITexture prefab problem with pixelInset.width 1 Answer

Deleting a Prefab when it is dragged to a GUI Texture 0 Answers

Canvas with GUI elements in prefab act strangely 0 Answers

Why is it important to create an empty gameobject for my prefabs? 0 Answers

Instantiating in Awake() v Setting up prefab instances in Editor performance difference? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges