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
2
Question by Aezora · Apr 04, 2017 at 05:16 AM · instantiate prefab

Button not instantiating, no errors

Hello,

I'm pretty new to the programming world, as such I am planning on running through the exact steps of my problem here. Note that I am using Unity 5.0.1, so if you think it is just a problem with the version I will upgrade (I'm just too lazy too, since there isnt much too of a difference).

First, I created a new scene. Then, I made a new button using the dropdown menu. I then changed its dimensions and such to my liking.

Next, I created an empty prefab, and then filled it with the button using drag and drop. To test if it was working, I deleted my button in the scene, then dragged and dropped the prefab on the scene, creating a new button.

Finally, I set out to instantiate the button using a script. This is the only line of code that I have related to this, all variables in it were properly set.

 GameObject chunk = Instantiate(Resources.Load("Chunk"), chunkMap[x,y,z].position, Quaternion.identity) as GameObject;

The prefab was named "Chunk". From what I can tell, this should create an object in the scene, which can be seen in the hierarchy, and at the location I set it to. However, nothing shows up on screen or in the hierarchy.

After some research the only thing that could possibly be needed additionally is a line of code somewhere that looks like var Chunk: GameObject; but anywhere I put that it doesn't seem to work.

Any time I run it I get no errors, any debug line I stick in there indicates that the code does reach, and pass that line. The "Chunk" prefab is in a Resources folder.

What am I missing (or doing wrong)?

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
0
Best Answer

Answer by Aezora · Apr 04, 2017 at 11:06 PM

Well, I figured it out. Turns out it was spawning in the wrong scene.... Because I was calling it from the wrong scene...

Well this is awkward.

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
1

Answer by AndreM1 · Apr 04, 2017 at 02:51 PM

That's really weird, I can't EXACTLY help your code since 5.0.1 is kinda outdated, but I can tell you what works for me in at least in 5.3. So maybe you want to test it if works.

You should really consider upgrading unity, there are some really nice features, and some weird bug fixes :)...

*You don't need to do Resources.Load(); do get a prefab from the source, this will cause performance issues everytime this code runs, instead, do this:

 using UnityEngine;
 using System.Collections.Generic;

 public class Script:MonoBehaviour{

     public GameObject chunkPrefab;

     GameObject ch = Instantiate<GameObject>(
       chunkPrefab, chunkMap[x,y,z].position, Quaternion.identity);
 }

or, you also might want to reference .localPosition, and remove the generic if you can.

 GameObject ch = Instantiate(
   chunkPrefab, chunkMap[x,y,z].localPosition, Quaternion.identity);

Comment
Add comment · Show 3 · 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 Aezora · Apr 04, 2017 at 03:13 PM 0
Share

Well, I tried this and it didn't seem to do anything. Although, when I tried to put <GameObject> next to the instantiate like you had, it gave me an unknown resolve error, so I ended up reverting to as GameObject. I guess I should probably update then...

avatar image AndreM1 Aezora · Apr 04, 2017 at 03:18 PM 0
Share

sorry then...

avatar image Aezora AndreM1 · Apr 04, 2017 at 03:23 PM 0
Share

No, thank you for answering.

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

How to replace prefab at the same location? 1 Answer

Instantiated Object does not fall 3 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


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