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 RoloJo · Feb 26, 2013 at 05:16 PM · instantiateprefabargumentexception

ArgumentException: The prefab you want to instantiate is null.

I am rather new to Unity and C#, and need help. I have looked around on the forums for people with similar problems but have yet to find anything that helps.

There are two game objects that need to be instantiated a wolf-object and a rabbit-object. I have scripted them in two different ways which seem the same to me. Why is does instantiating the wolf-object throw the above error and how can I correct this? In both cases the prefab has been assigned to their relevant scripts.

 using UnityEngine;
 using System;
 using System.Collections;
 using System.IO;
 using System.Linq;
 
 public class SpeciesCreation : MonoBehaviour {     
 
     public GameObject RabbitObj;
     
     int RabbitInit=30;
     
     WolfProps p=new WolfProps();
     
     void Start () 
     {    
         p.WolfCreate();
         
         for(int i=1;i<=RabbitInit;i++)
         {
             var RabbitObject = GameObject.Instantiate(RabbitObj, new Vector3((float)(UnityEngine.Random.value-0.5)*90f+50f,100.25f,(float)(UnityEngine.Random.value-0.5)*90f+50f),Quaternion.identity);
     }            
     }
     void Update ()
     {
         EquilibriumMathEngine.EquilibriumCalc();
     }
 }


 
 using UnityEngine;
 using System.Collections;
 
 public class WolfProps : MonoBehaviour 
 {    
     public GameObject WolfObj;
 
     
     public int WolfCreate()
     {
         {    
             var WolfObject = GameObject.Instantiate(WolfObj, new Vector3((float)(UnityEngine.Random.value-0.5)*90f+50f,101.25f,(float)(UnityEngine.Random.value-0.5)*90f+50f),Quaternion.identity);
             return 1;
         }
     }    
 }

Thank you in advance for any help :)

Comment
Add comment · Show 1
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 robertbu · Feb 26, 2013 at 07:19 PM 0
Share

I tried your script, and it worked fine. I tried a couple of things to produce errors, and was unable to produce the error you have above. A couple of things:

  • Attach a different prefab to the WolfObj. If it works, you know the issue is likely in the prefab and you'll want to exa$$anonymous$$e any scripts attached to the objects in the prefab.

  • If you still get error, check to make sure you don't have the the Wolf script attached to multiple objects.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by RoloJo · Feb 26, 2013 at 06:48 PM

Thanks for the reply.

I have dragged the prefab representing the Wolf-object into script and tried that. Then I dragged the script over onto the wolf prefab. Neither worked.

If I made the mistake that I think you are speaking of would it not give the following error: "UnassignedReferenceException: The variable has not been assigned."

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

9 People are following this question.

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

Related Questions

Can't instantiate bullets when calling shoot function in one script from another script. 1 Answer

Some Prefabs are not Loading 1 Answer

ArgumentException: The prefab you want to instantiate is null. 1 Answer

prefab instantiated by script containing ShadowCaster2D bugs out 0 Answers

Instantiate Object At Local Position 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