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 /
  • Help Room /
avatar image
0
Question by Slink472 · Sep 22, 2017 at 01:39 AM · prefabruntimeinstance

Accidentally editing prefab values at runtime

Hi, this may be a painfully simple question, but I've found that I am editing prefab variables at runtime rather than instances of them within the game. For example, I have an object that references a UI slider and changes it value through the use of a public variable I can assign in the inspector. I have prefabs of both of these objects. When I assign the slider's prefab to the accessing object's prefab, the instance of this accessing object within the game will edit the prefab's values of the slider rather than the slider that actually exists within the game. Is there any way to resolve this? Thank you for the help in advance!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by xvivax · Sep 22, 2017 at 02:12 AM

One of the problems might be, that you try to change prefab properties before Instantiating instance into the scene. In that case it going to change prefab rather than instance (which to be fare doesn't exist).

     public GameObject objPrefab;
     private GameObject inst;
 
     // Use this for initialization
     void Start () {
         // this will change prefab
         objPrefab.transform.localScale = new Vector3(2, 2, 2);
 
         inst = Instantiate(objPrefab, transform.position, Quaternion.identity);
 
         // this will change instance
         inst.transform.localScale = new Vector3(5, 5, 5);
     }

Comment
Add comment · Show 2 · Share
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
avatar image Slink472 · Sep 22, 2017 at 02:25 AM 0
Share

Hey, thanks for the reply! In the case I'm working with, the slider is present in the scene from the outset and the accessor is the one that is instantiated within the game. I'm noticing now that whenever I set public variables to prefabs though, that the object will refer to the prefab itself even when there are instances of that prefab within the game. I am realizing that I can't have any external connections between prefabs, that I have to find those connections at runtime ins$$anonymous$$d.

Thanks for the help figuring that out!

avatar image xvivax Slink472 · Sep 22, 2017 at 02:37 AM 0
Share

You welcome :)

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

86 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Editing prefabs at runtime 0 Answers

How to change the enum value of an instance of a prefab being clicked 0 Answers

Unity network manager assign playerprefab at runtime 0 Answers

How to detect if any prefab is instantiated in the scene from a script? 2 Answers

How to affect only one object out of many objects with the same name using script? 0 Answers


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