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 ina · Dec 28, 2010 at 11:34 AM · gameobjectinstantiatevariablebce0005bce0018

Setting the variable on a GameObject to be instantiated (not yet existent) cs and js

I'm trying to set an exposed variable on a gameobject that has not yet been instantiated.

var s:GameObject=GameObject.Find("instantiateMe");
var instances:GameObject;
instances = Instantiate(s,pos,rot);
instances.GetComponent(ScriptName).id=id;

Using the usual method above, I get this fatal error: "BCE0005 Unknown identifier: ScriptName"

instantiateMe (the object to be instantiated) has a script named ScriptName in it, with the global variable id...


Using this method, I get "BCE00018: The name 'ScriptName' does not denote a valid type ('not found')."

var s:GameObject=GameObject.Find("instantiateMe");
var instances:GameObject;
instances = Instantiate(s,pos,rot);
var script:ScriptName=instances.GetComponent(ScriptName);
script.id=id;

ScriptName.cs is a cs file! But, I'm using js on the other ones as I am more familiar with that.

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

2 Replies

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

Answer by StephanK · Dec 28, 2010 at 11:49 AM

It looks like you haven't defined the variable ScriptName anywhere in your code. GetComponent takes a string as a parameter not a type so you would have to write:

instances.GetComponent("ScriptName").id = id;
Comment
Add comment · Show 5 · 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 ina · Dec 28, 2010 at 12:00 PM 0
Share

No, that doesn't work because then Unity thinks we are calling Unity Components. Using your snippet, I get this other fatal error: "BCE0019: id is not a member of UnityEngine.Component"

avatar image StephanK · Dec 28, 2010 at 01:13 PM 0
Share

It's javascript? Try this: var script : ScriptName = instances.GetComponent("ScriptName"); script.id = id;

avatar image ina · Dec 28, 2010 at 01:45 PM 0
Share

tried that as well - "The name 'ScriptName' does not denote a valid type ('not found'). ..." - checked ScriptName, and it's clearly in instantiate$$anonymous$$e

avatar image StephanK · Dec 28, 2010 at 01:51 PM 0
Share

if ScriptName is not a type you either don't have a script that is named ScriptName.js or the compiler doesn't know about it. (Could be the case if it's in Editor or Plugins folder)

avatar image ina · Dec 28, 2010 at 02:45 PM 0
Share

It's ScriptName.cs

avatar image
0
Best Answer

Answer by Loius · Dec 28, 2010 at 04:00 PM

Try creating a folder called "plugins" or "Plugins" (not sure if capitalization is important) and putting your .cs files in there. THat'll cause them to be compiled earlier than most other scripts, and your .js files will know about their variables.

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

No one has followed this question yet.

Related Questions

Simple Dice Game - Error with Variable within an Instantiated Game Object (Prefab) - CS0118 and CS0119 Errors 2 Answers

How to set/get/change variables for newly spawned gameObjects? 1 Answer

Calling a variable 2 Answers

Passing a gameobject through two methods 0 Answers

Only change a variable on the instaniated object not the prefab. 0 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