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 ZanzibarDreams · Apr 13, 2011 at 01:44 PM · errorinstantiatebuildiphonebce0019

Scripting errors only when building for iPhone

I have encountered a problem when building for iPhone. It is strange because it only complains for when building for iphone, but then complains at the corrected code when I try it in the editor.

i get an error on these kind of lines.

var obj : GameObject = Instantiate( coinPrefab ).gameObject;

this returns: BCE0019: 'gameObject' is not a member of 'UnityEngine.Object'.

To get this code to build, I simply removed the ".gameObject", and then it compiles fine ( but only when building for iPhone, not for testing in editor )

So my question is: Is there something wrong with this code? Or is there a discrepancy in Unity?

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 13, 2011 at 02:30 PM 0
Share

I don't get why you'd do this... If you want to instantiate an object, wouldn't you just put the Instantiate code in? Is this what you're trying to do? $$anonymous$$aybe I'm reading this all wrong, but doesn't make sense to meeee, sorry.

avatar image ZanzibarDreams · Apr 13, 2011 at 02:38 PM 0
Share

thats what gives me an error when building for iPhone, if i only use Instantiate(coinPrefab), then i get an error in the editor

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by equalsequals · Apr 13, 2011 at 02:38 PM

Instantiate returns an Object, which does not have a gameObject property.

You would need to do something like this:

var obj : GameObject = Instantiate( coinPrefab ) as GameObject;

Hope that helps.

==

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 ZanzibarDreams · Apr 13, 2011 at 02:45 PM 0
Share

I'll try this out, but code from the scripting reference suggest that it should work even though it is an Object

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

in the second box :)

avatar image equalsequals · Apr 13, 2011 at 03:05 PM 0
Share

Well, yeah in some cases this would work due to the implicit typecasting allowed in Unity's JS. For example, it would work if you were instantiating a Component or some type of $$anonymous$$onobehaviour, because they have a .gameObject property, but since you are using Instantiate to instantiate a GameObject (your Prefab), if you check the docs the GameObject class has no .gameObject because it is a GameObject. $$anonymous$$ake sense?

avatar image
0

Answer by loopyllama · Apr 13, 2011 at 02:40 PM

Instantiate returns type Object which does not have a .gameObject

var obj : GameObject = (GameObject) (Instantiate( coinPrefab ));

or

var obj : GameObject = Instantiate( foo ) as GameObject;

or

var obj : GameObject = Instantiate( foo );

...are all correct ways

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 ZanzibarDreams · Apr 15, 2011 at 09:46 AM 0
Share

In my case noone of the above worked to solve the issue (both for the editor and for iphone). I did solve it however by using a Transform var as an intermediate:

var tobj : Transform = Instantiate( coinPrefab );//.gameObject; var obj : GameObject = tobj.gameObject;

avatar image loopyllama · Apr 15, 2011 at 12:57 PM 0
Share

it's impossible for us to know what type coinPrefab is. It could be a rigidbody for all we know. Only you and your code knows. The above answer is how to correctly cast in javascript! I am glad you have fixed your script!

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

Access JavaScript variables on c# script (Android build fails!) 1 Answer

Distribute terrain in zones 3 Answers

Why am I getting "X" is not a member of "Y" on Unity iPhone, when it works regular Unity? 1 Answer

xcode build fail - Mach-o linker error 3 Answers

115 errors in xcode 2 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