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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Squishlove · Nov 03, 2012 at 08:31 AM · prefabvariableassign

Failure to assign a prefab to a variable

When i run this script and the objects collide unity tells me i have failed to assign my prefab correctly(giving me the error "The Variable Cubeprefab of 'Cubeinteractions' has not been assigned" the moment there is a Collision). Any one care to help the scripting illiterate?

 using UnityEngine;
 using System.Collections;
 
 
 public class Cubeinteractions : MonoBehaviour {
     
     public Rigidbody Cubeprefab;
     
 void OnCollisionEnter(Collision collisioninfo){
     
         float boxmass = collisioninfo.rigidbody.mass;
         
         
         if(boxmass == rigidbody.mass){
             GameObject boxgameobject = collisioninfo.gameObject;
             Rigidbody Cube1 = Instantiate(Cubeprefab, transform.position, transform.rotation) as Rigidbody;
             Destroy(boxgameobject);
             Destroy (gameObject);
             }
             
     }
 }

I assume the problem is here "public Rigidbody Cubeprefab;"

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 Montraydavis · Nov 03, 2012 at 07:03 PM 0
Share

What error do you get ? We need more information on what the actual problem is . . . .

avatar image ZenithCode · Nov 03, 2012 at 07:28 PM 1
Share

Look in the inspector and see if the variable Rigidbody CubePrefab is none or not. Of it is you must assign an object there!

1 Reply

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

Answer by Chimera3D · Nov 04, 2012 at 08:20 AM

What ZenithCode said is right, in the Inspector panel in the Unity editor window when you click on the object that you've assigned the code to it should show the name of your code, below that there should be a slot that says "None (Game Object)". Drag and drop the prefab there and it should work. When you get this error the debugger is basically telling you that you didn't put anything in the slot or didn't have anything being automatically put in there (by code).

Comment
Add comment · Show 1 · 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 Squishlove · Nov 07, 2012 at 12:58 AM 0
Share

thank you, it's taken me awhile to see what you were talking about in the inspector. However thank you for your help, probably would have given up on that whole script without it.

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

12 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

Related Questions

Assign prefab to variable through script 1 Answer

How to make reference from prefab to variable via C#/JavaScript? 1 Answer

How to force a variable to prefab 1 Answer

Creating a Prefab and Keeping Original Objects Script Information 0 Answers

Are there restrictions on assigning GameObjects to Prefab script variables? 3 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