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 samzen · Nov 05, 2011 at 12:36 AM · instantiateprefab

instantiate problem with assigned variable

 var selectionPrefab : GameObject;
 var currentSelection : GameObject = Instantiate(selectionPrefab);

What I'm trying to do is that I've got a particle effect (emitter/animation/renderer) tied to a prefab that I want to instantiate.

The problem I'm having is regarding this error

UnassignedReferenceException: The variable selectionPrefab of 'rayCast' has not been assigned.

You probably need to assign the selectionPrefab variable of the rayCast script in the inspector. UnityEngine.Object.Instantiate (UnityEngine.Object original) (at C:/BuildAgent/work/842f9557127e852/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:56) rayCast.objectSelection () (at Assets/Scripts/rayCast.js:50) rayCast.Update () (at Assets/Scripts/rayCast.js:18) And the problem is really that it makes no sense. I've assigned it using the selection window. Tried dragging/dropping it into the variable slot and I've even tried declaring it in script (which didn't work very well). The script that's run isn't assigned to any object but is rather used for picking and movement. I don't know if that makes a difference or not. These few lines of code are driving me crazy, so any help would absolutely be 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

1 Reply

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

Answer by aldonaletto · Nov 05, 2011 at 12:47 AM

You may have a lost instance of this script attached to something, and this instance is producing the error. You can add to Start() a debugging line like this:

     print("I'm attached to "+transform.name);

You will see this message in the console for each instance of this script, and if there are more than one message, bingo! you found the culprit.

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 samzen · Nov 05, 2011 at 08:23 AM 0
Share

Thanks, that was kinda silly of me, I was assigning the variable directly to the script, not to the camera that it's attached to ^.^'

avatar image pedrord88 · Mar 19, 2014 at 02:15 PM 0
Share

What a clever answer!! It worked out with my problem too!! If I could I would vote your answer but apparently I don't have enough reputation :( Thanks!

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

How to Add Y Axis Offset to transform.localPosition on an Instantiated Prefab? 2 Answers

Instantiating one prefab with different materials in one frame 0 Answers

how to destroy camera instatiated from prefab? 0 Answers

Executing code on prefabs that are never instaciated + data loss 0 Answers

Enemy not spawning correctly 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