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 kurpnieks2 · Jun 06, 2016 at 01:39 PM · listlists

Missing objects upon List.Add();

Basically I have a list in which i need to get instances of a prefab. I instantiate them by using [ExecuteInEditMode]

Here's the line i'm using to instantiate it:

 enemyArray [i] = (GameObject)Instantiate (enemy, spawnPosition, Quaternion.Euler (0, 0, 0));

The problem is, when i try to add this gameobject to a list using Add(), i simply get lots of these "Missing GameObject" in the inspector, and i have created the list as new List() alongside declaring it aswell. I try to add them using foreach loop:

 foreach(Transform enemy in transform)
 {
     Debug.Log (enemy.name);
     enemies.Add (enemy.gameObject);
 }

Weird thing is, it actually debugs the names of the objects correctly. And another weird thing is if i just drag and drop this prefab into the scene, the Add() function will work, it simply won't work on the instances.

If anyone can tell me why it's happening this way, I will really appreciate it. Thanks.

Comment
Add comment · Show 3
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 Jessespike · Jun 06, 2016 at 08:30 PM 0
Share

Why use ExecuteInEdit$$anonymous$$ode? Have you tried not using it?

avatar image kurpnieks2 Jessespike · Jun 06, 2016 at 09:16 PM 0
Share

The thing is i'm doing this Add() with foreach loop in Start(). I am not sure but i think if i try to not use ExecuteInEdit$$anonymous$$ode and instantiate it on Start, foreach loop might have nothing to add since it happens on 2 different scripts and it could be over before anything is instantiated yet.

avatar image kurpnieks2 Jessespike · Jun 06, 2016 at 09:18 PM 0
Share

And another reason why i'm using it is because it's kinda easier for me to see where objects will be in game while i'm still in edit mode

1 Reply

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

Answer by Raresh · Jun 06, 2016 at 09:28 PM

For your usage scenario, i would use Gizmos. https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDrawGizmos.html http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDrawGizmosSelected.html

You can assign custom meshes to them, and they only draw in the Editor. This is what you are looking for :D

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 kurpnieks2 · Jun 07, 2016 at 06:06 AM 0
Share

This works. Thanks.

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

A node in a childnode? 1 Answer

How to find all similar elements in a list? 1 Answer

Adding item to list error? 2 Answers

List getting reversed? 0 Answers

How can you do calculations on two lists? 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