• 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 Malice · Apr 05, 2011 at 05:16 PM · transformparentpragmastrict

pragma transform.parent

Hi, i am new to strict pragma in javascript. I get this error: "transform is not a member of UnityEngine.Object"

This is the code I'm using:

var Sparks : ParticleEmitter;
var SparksInstance : GameObject = Instantiate (Sparks, BombPos.position, Bomb.rotation);
SparksInstance.transform.parent = Bomb;

Anyone has a suggestion?

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 burnumd · Apr 05, 2011 at 05:27 PM

Did you instantiate "SparksInstance" via script? If you look at the Instantiate documentation, you'll see it returns a UnityEngine.Object. But don't worry! If the object you instantiated is a GameObject, what you'll get back is also a GameObject, you just have to explicitly "cast" it as one:

//C# GameObject sparksInstance = (GameObject)Instantiate (sparksPrefab); // The "(GameObject)" in front of the Instantiate call treats the returned object as a GameObject.

//Javascript var sparksInstance : GameObject = Instantiate (sparksPrefab) // In Javascript/Unityscript, if you declare the type of the variable with its declaration, the compiler figures out what you mean to do.

ETA: Based on the code you added to your original question, you're making two steps at once. "Sparks" is a ParticleEmitter, not a GameObject. Now, it's attached to a GameObject, but you can't just treat it as one. Try this:

var SparksInstance : GameObject = (Instantiate (Sparks, Bomb.position, Bomb.rotation) as ParticleEmitter).gameObject;
Comment
Add comment · Show 4 · 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 burnumd · Apr 05, 2011 at 05:28 PM 0
Share

If you try to copy/paste this code, note that I've used the more typical first character lowercase for variable names. Adjust accordingly.

avatar image Malice · Apr 05, 2011 at 05:48 PM 0
Share

var SparksInstance : GameObject = Instantiate (Sparks, BombPos.position, Bomb.rotation); SparksInstance.transform.parent = Bomb;

When I try this, I'll get this error: "cannot convert UnityEngine.Object to UnityEngine.GameObject"

avatar image burnumd · Apr 05, 2011 at 06:29 PM 0
Share

See updated answer.

avatar image Malice · Apr 05, 2011 at 06:51 PM 0
Share

Thanks, it works great :D

avatar image
1

Answer by Statement · Apr 05, 2011 at 05:56 PM

I think it's because it returns a reference to the objects particle emitter, not a reference to the game object.

var SparksInstance : ParticleEmitter = Instantiate (Sparks, BombPos.position, Bomb.rotation); 
SparksInstance.transform.parent = Bomb;
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 Malice · Apr 05, 2011 at 06:07 PM 0
Share

When I try that i'll get this error: cannot convert UnityEngine.Object to UnityEngine.ParticleEmitter

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Manipulating booleans from parent to child (C#) 2 Answers

How to find if a child belongs to a Transform on RayCast Hit [Updated] 2 Answers

Moving child transform also moves parent rigidbody 0 Answers

Make a simple tree 1 Answer

Model rotation and hierarchy of game objects - not rotating! 1 Answer


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