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 seeker727 · Jan 02, 2019 at 11:07 PM · instantiate prefabbugsupdates

Instantiate Script Not Working After Update

Greetings,

I recently updated my unity to 2018.3.0b5 and attempted to update my project to this version as well.

There have been, of course, a few errors in the game, most of which I have been able to fix. However, one still remains and I'm not quite sure what to do.

The script I made to drop items (health and mana potions) no longer functions at all, but the compiler doesn't detect any errors.

Unity gives this message:


ArgumentException: The Object you want to instantiate is null. UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:383) UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Transform parent, Boolean instantiateInWorldSpace) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:262) UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original, UnityEngine.Transform parent, Boolean worldPositionStays) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:300) UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original, UnityEngine.Transform parent) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:295) ItemDrop.DropItem () (at Assets/Scripts/Enemy/ItemDrop.cs:35) EnemyHealth.TakeDamage (Int32 amount) (at Assets/Scripts/Enemy/EnemyHealth.cs:90) FireballController.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/Player/FireballController.cs:46)


I think the script that is not working is this one but I am not sure:

 public class ItemDrop : MonoBehaviour
 {
 
     public GameObject[] drops;
     private Rigidbody2D rb2d;
 
     public int spawnChanceThreshold = 7;
 
 
     void Start()
     {
 
         rb2d = GetComponent<Rigidbody2D>();
     }
 
     public void DropItem()
     {
         int itemSpawnChance = Random.Range(1, 10);
 
         if ((itemSpawnChance >= 1) && (itemSpawnChance < spawnChanceThreshold))
         {
             return;
         }
 
         else if (itemSpawnChance >= spawnChanceThreshold)
         {
             int itemToSpawn = Mathf.RoundToInt(Random.Range(0, drops.Length));
 
             Instantiate(drops[itemToSpawn], rb2d.transform.position, Quaternion.Euler(new Vector3(0, 0, 0)));
         }
     }
 }

Can anyone please point me in the right direction to fix this? I would be happy to share any code if additional information is needed.

Please note that this is my first game in Unity and my second time posting on the forums. I am aware that I have no idea what I'm doing, so helpful comments only please :)

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
2

Answer by austinsun102 · Jan 02, 2019 at 11:15 PM

Check the drops variable is not null in the hierarchy. If that’s not the problem then I don’t really know what it is. The argument basically means that the game object drops is null and when you try to instantiate drops, it can’t instant drops because it’s null.

Also: a little tip is instead of using quaternion.euler(new vector3 (0, 0, 0)), you can using Quaternion.identity and also if you ever want to use a vector 3 with a value of 0,0,0, you can use vector3.zero

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
avatar image
0

Answer by seeker727 · Jan 02, 2019 at 11:45 PM

Thank you for your input!

Apparently after instantiating the prefab enemy, the drops field (which is filled when the enemy is a prefab) becomes null when the enemy is in the hierarchy.

I was able to fix the issue by deleting the prefab, remaking it and re-filling the fields, and re-saving it as a new prefab.

Now I just have to do that with every single enemy prefab . . . . lol.

And thank you for the info about Quaternion.identity and vector3.zero. I will definitely use those going forward!

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 sean244 · Jan 03, 2019 at 02:54 AM 0
Share

Why are you posting this as an answer?

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

98 People are following this question.

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

Related Questions

Having problem with Instatiate GameObject at Canvas 0 Answers

Im trying to instantiate prefab from an array but get a confusing response...(this prefab will be consumed by the player meaning it needs to be instantiated multiple times) 2 Answers

Prefab attached to script is destroying itself before Instantiate() is called 1 Answer

Spawn a prefab off screen? 1 Answer

Instantiate, null reference and Raycasting problem. 2D 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