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 Kenji · Apr 12, 2011 at 09:56 PM · instantiateprefabbce0005

Instantiating Prefab from Javascript - BCE0005: Unknown identifier: 'Prefab'

Hello World!

When I try to instantiate a prefab from a script, I receive error message BCE0005: Unknown identifier: 'Sphere1'.

I have made the prefab so I don't understand why I'm getting the error message.

Here's how I made the prefab:


  1. Right clicked inside the "Project View" window->selected create->prefab.

  2. Clicked on GameObject->Create Other->Sphere.

  3. Dragged sphere in "Hierarchy" window onto prefab in "Project View" window.


Here's how I'm instantiating the prefab from the script:


function OnCollisionEnter(collision : Collision) {

var sphere_bullet : GameObject ; sphere_bullet = Instantiate(Sphere1,transform.position, transform.rotation) ; }


What I've done so far to try and solve the problem:

Checked "Overview: Instantiate" in Unity manual to see if I missed something:

http://unity3d.com/support/documentation/ScriptReference/index.Instantiate.html

Checked Overview: Script compilation (Advanced) in manual after reading some questions similar to mine:

http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html

Found out that Unity compiles scripts in a certain order leaving in "editor" scripts for last.

Tried changing position of prefab and script in case the script was being compiled before Unity knew anything about the prefab.

Created a new project with a new script and prefab made the same way without any other folders or assets.

Searched Unity Answers for people with the same problem but I couldn't find a solution that worked for me.

Other Information:

The script code isn't contained in any other functions.

The only objects in the "Project View" window are the prefab and the script.

I named the prefab "Sphere1".

Any help would be great.

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 Justin Warner · Apr 12, 2011 at 10:09 PM 0
Share

You named the prefab sphere1, but did you get the Sphere1 a var name? Like, above the instantiate function, did you do var Sphere1 = ___?

avatar image DaveA · Apr 12, 2011 at 10:12 PM 0
Share

... and assign it in script or Inspector?

2 Replies

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

Answer by flaviusxvii · Apr 12, 2011 at 10:11 PM

You need something like:

public var Sphere1:GameObject;

in your script. Then you need to link your prefab to that variable in the script (drag and drop).

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 Kenji · Apr 13, 2011 at 07:33 AM 0
Share

Thank you for the help. It worked after I added this into the code. I was ecstatic! I can make stuff instantiate now!

avatar image
2

Answer by DaveA · Apr 12, 2011 at 10:13 PM

You mentioned editor scripts, is yours an editor script? If so, did you look here: http://unity3d.com/support/documentation/ScriptReference/EditorUtility.InstantiatePrefab.html

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 Kenji · Apr 13, 2011 at 07:34 AM 0
Share

Thanks for the help. You didn't answer my question but I tried running the script you gave me. It works really nicely for quickly generating prefabs with a 1-2 click.

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

No one has followed this question yet.

Related Questions

Instantiated Prefab's script doesn't work 2 Answers

How to access script variables attached to a prefab at runtime in Javascript? 2 Answers

Calling a function from a instantiated clone 1 Answer

[Solved]Instantiating prefab from a script and destroy it from another one 2 Answers

How to use EditorUtility.InstantiatePrefab? 5 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