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 TSI25 · Jul 19, 2014 at 12:44 AM · gameobjectprefabpublic variable

Can't assign variable to prefab, or apply changes to prefab.

just like i said in the question. I have a game object im trying to track in a script, i declared a public variable with the intention of dragging and dropping the game object into the script that was attached to a prefab - but it didn't allow me to assign it. Then i put the prefab in the scene and again tried to assign the variable. This time it let me drag the object in, however it wouldnt let me apply changes. Heres the script

 using UnityEngine;
 using System.Collections;
 
 public class Planet : MonoBehaviour {
 
     public float size;
     public float speed;
     public float speedMin;
     public float speedMax;
     public Vector3 position;
     public double mass;
 
     public GameObject pivot;
     public GameObject planetMenuRoot;
 
 
     void Start()
     {
         speed = Random.Range(speedMin, speedMax);
     }
 
 
     void OnTriggerEnter()
     {
         Debug.Log ("planet entered");
         planetMenuRoot.SetActive(true);
         AstraeusFlight.inPlanet = true;
         AstraeusFlight.planet = gameObject.transform;
     }
 
 
     void Update()
     {
         transform.RotateAround(Vector3.zero, Vector3.up, speed * Time.deltaTime);
     }
 }

the variable im attempting to assign is the planetMenuRoot which is an empty game object inside of an NGUI panel. I have also tried spawning a cube and an empty game object and attaching those to the script on the prefab - no luck. anyone know whats going on?

Comment
Add comment · Show 2
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 iwaldrop · Jul 19, 2014 at 02:25 AM 0
Share

I'm afraid you haven't made it terribly clear what you tried that didn't work.

avatar image TSI25 · Jul 19, 2014 at 04:31 AM 0
Share

I'll see if i can explain more clearly. I wrote the script i posted above which has a public variable in it - planet$$anonymous$$enuRoot. I then made a prefab that has that script attached to it. then i selected the prefab from the project panel such that i could see all of its components in the inspector window. then i attempted to drag and drop the planet menu root game object into the planet$$anonymous$$enuRoot variable slot in the planet script of the prefab. this didn't work - the variable simply didnt assign.

Then i dragged the prefab into the scene. then i selected the prefab in the scene hierarchy such that i could see all of its components in the inspector window. then i attempted to drag and drop the planet menu root game object into the planet$$anonymous$$enuRoot variable slot in the planet script of the prefab. this time the variable assigned just as it was supposed to. when i hit "apply" in the inspector window - in the hopes of applying this change to all prefabs - it didnt apply the changes and ins$$anonymous$$d the prefab in the project view remained without the assigned variable.

Lastly i tried dragging the prefab in the scene over the prefab in the project panel in the hopes of over-writing with a version of the prefab that had the variable assigned. This still did not work.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TSI25 · Jul 20, 2014 at 09:02 PM

looks like i can only assign prefabs from the project panel, or children of the game object that the script is attached to. this is way more restrictive than i remember assigning public variables to be but i guess these are parameters i can work with.

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

22 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

Related Questions

Cloned/Instantiated GameObject's Losing Public Variables When Created? 1 Answer

Spawn Prefabs 1 Answer

Creating an array of prefabs? 4 Answers

Replacing empty gameobjects with prefabs 3 Answers

Change the colour of a prefab with a script. 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