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 serenefox · Mar 16, 2013 at 07:02 PM · instantiateprefabinspector

Problem with assigning a something to a prefab

I created a question here last night and was led to the real problem behind that question but it still never got answered. And now more of the same problems are popping up in my unity file. I have tried googling everything I could think of and nothing that helped. I will post the link to the other question for reference at the bottom if needed. So here is the problem I am having:

When a "clone" of my player is instantiated the clone doesn't have everything the original "player" has that was in my scene. Example one: When my player object respawns it should have an empty gameObject attached as a child that is tagged target. It doesn't have it and now one of my enemies doesn't "LookAt" with my script but it did before the player died.

Example two: I have an audio source that is attached to the player and a script that is on the player that tells where that audio source is to enable it. It works perfectly until the player respawns after dying, then I get a null reference exception because the part in the inspector where I had assigned it is set to none when I checked.

It's like its not saving the prefab. And yes I first "applied" the "player" in my scene, then since that didn't work I tried dragging and dropping the player prefab from the scene back onto the player prefab in the project folders area. It shows that its there in the project view and when I drag it back into the scene it has everything on it, but again when a clone is instantiated it doesn't have certain things.

Here is the link to the previous question since it has some of the scripts (even though I don't think it is a problem with the scripts): http://answers.unity3d.com/questions/417949/semi-quick-question-about-lookat-script-after-resp.html

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 serenefox · Mar 16, 2013 at 07:09 PM 0
Share

I guess I should probably ask why for it to be a question. So why is my prefab not saving when it gets instantiated as a clone? And is there a way around this or to fix it?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Loius · Mar 16, 2013 at 07:17 PM

If you instantiate from a prefab, you'll always get a copy of the prefab. In order to not get a full copy of the prefab, you'd have to alter the prefab - are you using the prefab instead of the instantiated object somewhere?

Failing that, if you have 'initial spawn' code AND 'respawn' code, then your respawn code is doing something it shouldn't and we'd need to take a look at it.

Also, pause the game just after a respawn and examine the clone - find the exact differences between it and your desired outcome, and see if you can work it out from there.

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 serenefox · Mar 16, 2013 at 07:27 PM 0
Share

I have already looked at the clone and the original and I do see the missing items but I still don't see how to fix it. I dont have an initial spawn code (the player is already in the scene when the game starts) but here is my Respawn code (the player is attached to the main camera):

 #pragma strict
 
 private var player : GameObject;
 var lives : int = 3;
 var playerspawnPoint : GameObject;
 var playerOne : GameObject;
 var respawnStarted : boolean = false;
 
 function Update()
 {
     
     player = GameObject.FindWithTag("Player");
     if(!player && !respawnStarted)
     {
         RespawnInstructions();
     }
 }
 
 
 
 
 function RespawnInstructions()
 {
     respawnStarted = true;
     lives--;
     if(lives <= 0)
     {
         yield WaitForSeconds(3.5);
         Application.LoadLevel("Aliens$$anonymous$$ain$$anonymous$$enu");
     
     }
     else
     {
         yield WaitForSeconds(2);
         var newPlayer : GameObject = Instantiate(playerOne, playerspawnPoint.transform.position, playerspawnPoint.transform.rotation);
         newPlayer.transform.parent = Camera.main.transform;
     }
     respawnStarted = false;    
 }
avatar image serenefox · Mar 16, 2013 at 07:36 PM 0
Share

Thank you for your help I guess I am just too tired and have been working on this for too long I am starting to miss the small things. The problem was I had the "plane" under the camera as a prefab and a plane prefab itself and was instantaiting the plane as a replacement ins$$anonymous$$d of the camera "plane". I must be losing it. Sorry everyone that was helping me haha. But thank you anyway.

But thank you for your answer Loius if it wasn't for the pause and look at it again anyway line(which I had been doing for the past two days) I wouldn't have seen that I had another prefab of the plane hidden away. I had pretty much given up on that.

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

11 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

Related Questions

Adding behaviors to a game object at run time via scriptable object 1 Answer

Linking prefabs 0 Answers

How to set a default prefab on a C# script? 1 Answer

Unity not Instantiating as Prefab 1 Answer

How can i assign prefab to variable without drag & drop from project to inspector. 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