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
1
Question by Regone · Oct 04, 2014 at 03:06 AM · c#gameobjectprefabinspectorchanges

Staged Prefab can't "Apply" after adding using Gameobject as a variable

so im practicing on making games and i never really finished a game so im not that experienced in making one especially in unity

i was making prefabs and wanted to link the Player character gameobject (which is a prefab aswell) to the enemy to use his functions but when i try to apply the changes so that everyother badguy will use it after he spawns it wont let me save the changes i made and the changed parameters stays bold (Example i captured http://i.gyazo.com/813584dab84b258982cde7c360dfc584.gif)

at first this issue was happening while changing the badguy but right now it happens in almost every prefab especially when trying to link between to gameobjects in the inspector by a script call

(example:

     (C#)
     ...
     public GUIText Score;
     public PlayerControls playscr;        
     ...

)

im almost hopeless and because of that i cant continue most of my plans, any suggestions?

EDIT:

I noticed that i can apply any parameter now but can't only game objects that are in the scene alt text

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
3

Answer by _dns_ · Oct 04, 2014 at 04:18 PM

Hi, that's the expected behavior ! In a Prefab, you can't reference an object that is in a scene. A prefab exist on disk, it has a path to an Asset file. An object in a scene is an Instance that exists only in memory when the scene is loaded. You can't reference something in memory from something on the hard drive (only the other way around is valid)

Imagine you could reference an instance: You have "PrefabP" that references "ObjectInstanceA" in "SceneA". Now you create a second new scene "SceneB". You drop "PrefabP" in "SceneB". How can this object instance reference an object "ObjectA" that is in "SceneA" only, and only when "SceneA" is loaded, which is not the case.

I'm not sure exactly what you need to do, but what is possible is to reference a prefab from another prefab: you can drag & drop a prefab in a property field of another prefab. For example, a Hero class prefab could have a MainWeapon property. A Hero.MainWeapon of a Hero prefab could reference an Axe prefab. Then, when the Hero prefab is instantiated in memory in a scene, Unity will automatically create an instance of the Axe prefab and reference it in the Hero.MainWeapon instance. Warning: when playing from the Editor, any change made to the Axe object will be changed in the prefab file too, so this solution is not always ideal. Also, if multiple objects reference the same Axe prefab, they will reference the same instance in memory so there may be conflicts when modifying properties. Then, you may want to Instantiate() the Axe prefab yourself during Awake() or Start() to create an independent instance.

For your case: if you need your Enemy to reference your Player in a scene: in the Awake() or Start() function of the Enemy: use FindObjectWithTag or FindObject to find the player instance in the scene and assign it to playscr.

Well, difficult to explain that clearly here, I would recommend reading docs or tutorials about prefab and instances

Comment
Add comment · 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

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

Prefab not loading in data from Inspector 1 Answer

Spawning a prefab at another object's location 3 Answers

How to associate underlying data structure to prefab at runtime? 1 Answer

Get Script from gameobject knowing only parent script 1 Answer

Changes made in prefab mode via script aren't marking the object as Dirty 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