• 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 yoyotan8080 · Sep 11, 2016 at 04:57 PM · gameobjectlocationspawning problems

How can i spawn a prefab at an empty game object? C#

I tried scripting it casually but gets an error Object reference not set to an instance of an Object C#.

Comment
Add comment · Show 2
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 Cherno · Sep 11, 2016 at 05:42 PM 0
Share

Please rewrite your question, it is not clear what you want. If you want to instantiate an empty GameObject, you actually don't use Instantaite, but rather just delcare a new GameObject variable and an empty GO will appear at position 0,0,0.

avatar image ShadyProductions · Sep 12, 2016 at 09:54 AM 0
Share

Do you mean something like gameObject.Position = emptyObj.Position; ? Rephrase your question please.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Hraesvelgr-tc · Sep 11, 2016 at 06:05 PM

im not sure if this helps but i think your trying to make an empty GameObject become say a map

 void mapGen()
     {
         mapGenerator mapBuild = GetComponent<mapGenerator> () as mapGenerator;
         mapBuild.generateMap();
     }

so for the longest time i was getting the same null exception reference. the object in the scene the script is attached to i detached it and than in the void start i just loaded it like so.

 void Start () 
     {    
         gameObject.AddComponent<meshbuilder> ();
     }

im by no means an expert but im pretty sure the null exception reference has to do with the fact your not pointing or making any reference to the actual gameobject in scene nor are you making a new one. so there is an error, not with the code itself but that to unity theres no object to change.

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 yoyotan8080 · Sep 12, 2016 at 03:14 AM 0
Share

i meant spawning a gameobject at a specific location(empty object) like spawning point

avatar image Hraesvelgr-tc yoyotan8080 · Sep 12, 2016 at 03:44 AM 0
Share

oh ok if theres no gameobj than like cherno said just saying GameObject spawns a empty gameobj. if you want that gameobj thats empty at a specificied location than change its transform. but to make an empty obj into a cube capsule or w/e you need to change or add a mesh at least

avatar image
0

Answer by rajan4uto · Sep 12, 2016 at 10:05 AM

GameObject obj=(GameObject)Instantiate(prefab, "empty game object position", Quaternion.identity);

if you want to spawn object as a child of empty gameobject then add this code : obj.transform.parent=emptygameobject.transform;

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

How to swap 2 game objects from any position on a 2d game pad? 0 Answers

[Solved] Make GameObjects spawn at custom locations (Slender like) 2 Answers

spawn an object at the location of an empty gameobject 1 Answer

Instantiating Multiple Game Objects to the Position of a Current GameObject 2 Answers

Best way to determine if there is a gameobject in multiple locations? 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