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
1
Question by jlevy · Aug 01, 2011 at 04:15 PM · instantiatelist

About Instantiate

 private ArrayList ListA = new ArrayList();
 
 ListA.Add(Instantiate(PrefabA,transform.position, Quaternion.identity) as GameObject);
 
 Debug.Log(ListA[0]);

I wonder why the console give me a "null" ~~ Thanks

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 superventure · Aug 01, 2011 at 04:49 PM 0
Share

I don't understand the code...You did specify the prefab you want to instantiate? Besides if you want to add something to an array, don't you use the 'push' command? then you say to instantiate ListA[something].

avatar image Crazydadz · Aug 01, 2011 at 06:54 PM 0
Share

with a bigger explanation of what you want to do it will help us to help you hehe

2 Replies

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

Answer by BigBulle · Aug 01, 2011 at 09:09 PM

Try this :

 ListA.Add((GameObject)Instantiate(PrefabA,transform.position, Quaternion.identity));

You should obtain an nice exception :-).

The 'as' operator return null if the cast fails. So I guess that your are not instantiating a game object...

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 aldonaletto · Aug 01, 2011 at 09:27 PM 0
Share

Instantiate returns the same type declared in PrefabA. @BigBulle is right: probably PrefabA was declared as Transform or other type different from GameObject, what caused the problem. Declare PrefabA as GameObject:

  public GameObject PrefabA; // I suppose you're using C#
avatar image
0

Answer by jlevy · Aug 02, 2011 at 04:19 AM

thanks BigBullee & aldonaletto both of you are right

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Checking if object intersects? 1 Answer

How to find index of a list? 3 Answers

How do we instantiate random sprites from an array... 1 Answer

Game object instantiated and added to list but the change in capacity shows that 4 game objects have been added to the list? 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