Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 blueGaia · Oct 01, 2011 at 06:46 PM · javascriptprefabdirectory

How do you set a Prefab through javascript?

var waypointPrefab : Prefab;

//i just want to set it here...

function Start () {

waypointPrefab = ...(users/***/Prefabs/e.c.t);

}

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
1
Best Answer

Answer by aldonaletto · Oct 01, 2011 at 07:42 PM

You usually set the prefabs at the Inspector. You can also read objects from the Resources folder and assign them to prefabs - or even instantiate directly from the resource read. Take a look at Resources.Load - the docs have some useful examples.

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 blueGaia · Oct 01, 2011 at 08:06 PM 0
Share

cool, looks like Resources.Load will help. thanx It is set in the inspector but i am trying to make it so all i need to do is drop my unit.js on any unit and it will function. And also to clean up the inspector so it holds only what is needed, bit easier on the eye like, OCD really ;)

avatar image Bunny83 · Oct 02, 2011 at 03:20 AM 1
Share

But the Resources folder have some disadvantages:

  • Unity will include all stuff in those folders even if you don't use it

  • In Webbuilds you can't control when those files are loaded. Unity will load them even before the first scene to make sure all is available. This can increase the loading time.

  • The access is a bit slower since Unity have to find the object via path-string ins$$anonymous$$d of using a direct reference.

If you select your script file in your project-panel (not a GameObject in the hierachy, the script file itself) you can setup the default-references. Those references can only be set to objects from the project-panel. It's not possible to assign something from the current scene (aka hierachy-panel). If you assigned a default reference Unity will automatically assign this reference when you attach this script to a GameObject. Already attached instances are not affected. It's just a little help to simplify the setup-process for your scripts so you don't need to assign the prefabs manually all the time.

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

Instantiate a Prefab thats been passed through 2 scripts? 2 Answers

Script is working incorrectly. (rotation) 1 Answer

Monster Spawner 3 Answers

Set a Prefab's variable when you instantiate it, but before it calls Awake? 2 Answers

Need help understanding scripted prefab behavior - when I click one, the script runs on ALL prefab instances, not just the one I clicked. 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