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 /
This question was closed Jun 15, 2017 at 12:17 PM by Parksters for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Parksters · Jun 14, 2017 at 08:23 PM · instantiateprefabnullargumentexception

Some Prefabs are not Loading

I am using six prefabs right now: Cross, Straight, Curve, End, Tee, Blank. All of them load and are able to be instantiated, except for End and Tee, which when I try to instantiate either, give the error "ArgumentException: The prefab you want to instantiate is null."

I load everything here:

         public GameObject fabCross_Tile = Resources.Load("Cross") as GameObject;
         public GameObject fabStraight_Tile = Resources.Load("Straight") as GameObject;
         public GameObject fabCurve_Tile = Resources.Load("Curve") as GameObject;
         public GameObject fabEnd_Tile = Resources.Load("End") as GameObject;
         public GameObject fabTee_Tile = Resources.Load("Tee") as GameObject;
         public GameObject fabBlank_Tile = Resources.Load("Blank") as GameObject;

I initialize everything here:

         public void initialize_cross ()
         {
             entity = fabCross_Tile;
             t_top = 1;
             t_right = 1;
             t_bottom = 1;
             t_left = 1;
 
             print (entity);
         }
 
         public void initialize_straight ()
         {
             entity = fabStraight_Tile;
             t_top = 1;
             t_right = -1;
             t_bottom = 1;
             t_left = -1;
 
             print (entity);
         }
 
         public void initialize_curve ()
         {
             entity = fabCurve_Tile;
             t_top = 1;
             t_right = -1;
             t_bottom = -1;
             t_left = 1;
 
             print (entity);
         }
 
         public void initialize_end ()
         {
             entity = fabEnd_Tile;
             t_top = 1;
             t_right = -1;
             t_bottom = -1;
             t_left = -1;
 
             print (entity);
         }
         
         public void initialize_tee ()
         {
             entity = fabTee_Tile;
             t_top = 1;
             t_right = 1;
             t_bottom = -1;
             t_left = 1;
 
             print (entity);
         }
 
         public void initialize_blank ()
         {
             entity = fabBlank_Tile;
             t_top = -1;
             t_right = -1;
             t_bottom = -1;
             t_left = -1;
 
             print (entity);
         }

At this point, it prints out Null for End and Tee, but the correct values for everything else.

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 Cynikal ♦ · Jun 14, 2017 at 09:06 PM 0
Share

If it's returning null, then it can't find it.

You should check the spelling for the "End" and "Tee" within your resources to make sure you're loading the exact file.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by eskivor · Jun 15, 2017 at 07:59 AM

are these prefabs well named in the resources folder ?

Comment
Add comment · Show 2 · 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 Parksters · Jun 15, 2017 at 12:12 PM 0
Share

Hmm ... I tried changing the names to a few different things, and anything other than "End" and "Tee" seemed to work, though I have no idea why.

avatar image eskivor Parksters · Jun 23, 2017 at 03:44 AM 0
Share

Are you sure that

 public GameObject fabEnd_Tile = Resources.Load("End") as GameObject;
 public GameObject fabTee_Tile = Resources.Load("Tee") as GameObject;

is executed ? Your script is not entire here, do you execute all these lines in only one function or separate ones ?

You do not uploaded the scripts that also execute the initialize functions, can you do it, are you sure that all of these initializefunctions are executed ?

Ultimately, if it's still not those solutions just above, can you upload your project somewhere online and share a link in this topic ? (If it's a big project, create a empty new one, and put it only the problematic parts)

Otherwise, your initialize script can be refactored to something way more shorter like this (while assu$$anonymous$$g that t_top, t_right, t_bottom, t_left are variables of type int, else replace intby their correct type (float, etc.)) :

 public void Initialize (GameObject prefabObject, int t_topValue, int t_rightValue, int t_bottomValue, int t_leftValue)
 {
              entity = prefabObject;
              t_top = t_topValue;
              t_right = t_rightValue;
              t_bottom = t_bottomValue;
              t_left = t_leftValue;
  
              print (entity);
 }
 
 public void initialize_cross ()
 {
              Initialize (fabCross_Tile, 1, 1, 1, 1);
 }
 
 public void initialize_straight ()
 {
              Initialize (fabStraight_Tile, 1, -1, 1, 1);
 }
  
 public void initialize_curve ()
 {
              Initialize (fabCurve_Tile, 1, -1, -1, 1);
 }
  
 public void initialize_end ()
 {
              Initialize (fabEnd_Tile, 1, -1, -1, -1);
 }
          
 public void initialize_tee ()
 {
             Initialize (fabTee_Tile, 1, 1, -1, 1);
 }
  
 public void initialize_blank ()
 {
             Initialize (fabBlank_Tile, -1, -1, -1, -1);
 }

Follow this Question

Answers Answers and Comments

91 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

Related Questions

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

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

Instantiating prefab from another script. Error, prefab is null. 1 Answer

prefab is null when I try to instantiate from another script 1 Answer

Game Object seems empty after instantiation 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