Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Instantiated Prefabs are missing Canvas child components

Discussion in 'Scripting' started by Unlimited_Energy, Aug 8, 2017.

  1. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    I noticed that my prefabs that are instantiated as clones are missing specific child objects that are part of their prefab. I have saved these prefabs and made sure 5 times they are saved but they are missing a canvas object which also holds multiple UI elements and a status bar. Any idea why my prefabs that are instantiated are missing these? The first image is the original prefab and second is the instantiated clone.
     

    Attached Files:

  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I don't see your object at all in your issue2.JPG
     
    Unlimited_Energy and Magiichan like this.
  3. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    You seem to have cropped issue2.JPG incorrectly.
     
    Unlimited_Energy likes this.
  4. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    Here is what the hierarchy looks like for the instantiated clone. You can see it is missing the canvas with all the child objects also attached to the canvas. Ultimate UI Canvas Object should be below the particleSystem object but you can see it is missing on the instantiated clone.
     

    Attached Files:

  5. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    That is exactly the point im making. It is missing on the clone. the screenshot with the Ultimate UI Canvas is the Prefab I have in my scene. Dragging a new prefab has the Ultimate UI canvas object on it, Instantiated Clones do not.

    If anyone has a solution or answer for this you are going to make my day. Been looking high and low on google for an answer with no avail.
     
    Last edited: Aug 12, 2017
  6. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    Hmm, no one has any idea I guess on why instatiated prefabs would be missing objects from their prefab. Even when they are assured to be saved on the ooriginalprefab.
     
  7. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    Would you mind sharing your code?
     
    Unlimited_Energy likes this.
  8. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    Instantiate (seedClone, SeedRespawn.position, SeedRespawn.rotation);

    That is the line of code I am instantiating the prefab from. Nothing special. On the original model I imported I was able to add a particle system which you can see saved, but the Ultimate UI Canvas is not part of the instantiated prefab.

    I JUST tested adding a simple cube and It seems Nothing I add to any of my prefabs is saving at all...... its like I cannot add anything else to them. I mean it saves on the prefab but any one of the 24 different prefabs I have will not instantiate any of the new changes to them.
     
    Last edited: Aug 13, 2017
  9. dpgdemos

    dpgdemos

    Joined:
    Apr 28, 2014
    Posts:
    24
    In your inspector, are you sure that you have added the correct 'seedClone' game object? Do you possibly have an old prefab that you forgot to delete or replace?
     
    Unlimited_Energy and Magiichan like this.
  10. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    I Figured it out, SUPER WEIRD. I had to re drag all 24 prefabs from the projects folder into the inspector fields again. There are no duplicates of these prefabs, so this is where they are instantiated from. The inspector was holding on to older versions of the prefab, even tho there are only one copy of it. Its like it never updated some weird reference to it within the inspector. If I only have 1 set of these prefabs, and I make a change to them and hit apply changes to prefab, why would unity make me redrag that prefab into a field in the inspector and where is the old version being stored at? This seems like a bug.
     
    Magiichan likes this.
  11. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    Yeah, that is very weird.
    Do you know a way to reproduce this bug?
     
    Unlimited_Energy likes this.
  12. dpgdemos

    dpgdemos

    Joined:
    Apr 28, 2014
    Posts:
    24
    @sunseeker1988 that is really odd. I've had things like that happen in the past. Sometimes Unity will cache some unwanted behavior. I would try restarting the editor and even rebooting your system.
     
    Unlimited_Energy likes this.
  13. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    Things like this drive me NUTS with unity because it will eat up an entire week of my time:mad:. Thanks, guys. I would have no idea how to reproduce the bug, unfortunately.
     
    Magiichan and dpgdemos like this.
  14. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    902
    I'm having this exact bug in Unity 2019.1.8f1, now found @ the top of Google, @sunseeker1988 . I have not resolved it yet, but will try what you mentioned. Same deal - if I try the prefab directly in from Project, it has the children. However, when instantiated, the children are now missing! The prefab wasn't changed at all.

    Unfortunately, I don't have any repo info -- just that the exact post happened to me.

    Update: Restarting Unity worked for me. That was SUPER weird! This seems to still a rare bug.

    Update 2: Nope, it's back, but only for 1 of the 2 calls. Same prefab, re-dragged in to confirm, 1 has parent, 1 doesn't. Copy+Paste code, same prefab, same func. Just called from a different instance (eg, 1 called from 'fighter', 1 called from 'wizard').

    Update 3: Anddd, it's fixed. With nothing changed but stopping + starting. Children are back! This is a horrible bug that I wish I could repro. It's so random.
     
    Last edited: Aug 22, 2019
    Unlimited_Energy likes this.
  15. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    Try this. Make sure all of the prefabs you want to fix are in your hierarchy. All the hierarchy prefabs should be what you want to instantiate. Delete the prefabs inside your project folder and then re create those prefabs from your hierarchy prefabs(which after deleting the project ones will turn your hierarchy prefabs red I believe and back to just regular objects until you re drag them into your project folder to create the prefab. This should "erase" any trace of old prefab issues or that prefab at all from unity. now you have fresh new prefabs with what you want to instantiate.
     
    MrLucid72 likes this.
  16. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    902
    Seems to be working now -- most likely because of this, or the chance of sheer luck of a few Unity restarts (since it kept going and coming back). Haven't seen it revert all day, so seems good. The 1st one never reverted back - just that once. Just this 2nd one that was weird.

    Thanks! Wish I know what caused this.
     
    Unlimited_Energy likes this.