Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 zpinner · Feb 28, 2012 at 10:04 PM · prefab

Setting attribute in prefab

I have an object referencing a prefab which was setted by drag'n drop at "public GameObject gameObjectRef" When I set an attribute on gameObjectRef, it alters the prefab directly and the change is keeped even after stopping the game and starting it again. Is it possible to set this variable without alter the prefab object?

Comment
Add comment · Show 6
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 jspease · Feb 29, 2012 at 06:42 AM 1
Share

So you're asking "How can I edit a prefab without editing it"? This is kind of unusual. Can you explain more what exactly you're trying to do? I think it's basically possible but I don't want to suggest something too complicated if you're not actually trying to do that. Why not create an instance of the prefab with Object.Instantiate and then set the attribute on that?

avatar image zpinner · Feb 29, 2012 at 10:34 AM 0
Share

Well, yes, if I edit variables through inspector in game mode, those variables are not kept, right? I want to keep the prefabs as instance of objects, and change only them without changing the "class". Right now I'm thinking on instantiating the prefab and put it on position (-999,-999,-999) just to have a object that I can set variables.

avatar image jspease · Feb 29, 2012 at 05:43 PM 0
Share

Actually no, if you select a prefab in the inpector and edit the variables on it during game mode, those changes ARE kept too. They aren't kept if you edit them on an instance of the prefab. The usual thing to do is to instantiate the prefab (if the position doesn't matter then you don't even need to bother putting it at any position) and only use and change that instance while the game is running.

Also, I've found it useful to have a convention where I put "prefab" in the variable name of anything that's supposed to be a prefab dragged in in the inspector, so if I see something called gameObjectPrefab (for example) I know that the only thing I should ever do with it is call Instantiate on it, not change its attributes.

avatar image zpinner · Feb 29, 2012 at 05:59 PM 0
Share

yeah, that's what I'm doing, but it feels not performatic. how expensive is to instantiate a prefab? will it consume vram (using a vertex buffer for the renderer and etc) or just the normal memory to keep the object data?

avatar image jspease · Feb 29, 2012 at 06:30 PM 0
Share

It's expensive if you're instantiating it every frame, but if you just do it once when your game or level starts up then it's not that bad. And things that consume VRA$$anonymous$$ are shared assets which get loaded if your prefab is even referenced by the scene, and they won't get loaded twice (and a prefab is rarely if ever rendered directly) so you don't need to worry about that. By the way, it is technically O$$anonymous$$ to modify prefabs while the game is running in a built player (a final build running on someone's computer can't possibly change the assets in your editor, after all), so you could put #if UNITY_EDITOR then change the prefab #else use an instance of the prefab, but it sounds like a premature optimization to me.

Show more comments

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

6 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Is there a way to set components in a prefab before it is Instantiated? 0 Answers

How to associate prefab with a variable in C#? 1 Answer

ThreadCheck error when making Prefabs 1 Answer

How do I script a prefab like I would code a class? 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