Search Unity

Enabling or adding a Renderer during rendering

Discussion in '2D' started by Blobfish, Feb 22, 2017.

  1. Blobfish

    Blobfish

    Joined:
    Feb 28, 2013
    Posts:
    30
    Hello,

    I suddenly get this error that says:
    and then the same for 3 other objects in the same prefab called "score_board, play_again and home". The prefab looks like this:
    v2yk4.png

    Every object mentioned in the error has a Sprite Renderer attached. This is the code that instantiates the object:
    Code (CSharp):
    1. GameObject go = (GameObject)Resources.Load("GameOverScreen", typeof(GameObject));
    2. go.transform.position = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 1, 10));
    3. GameOverScreen gos = go.GetComponent<GameOverScreen>();
    4. gos.scoreLabel.GetComponent<Text>().text = score.ToString();
    5. gos.bestScoreLabel.GetComponent<Text>().text = highscore.ToString();
    6. Instantiate(go);
    I'm not sure if i have updated unity or done nothing at all since it stopped working but i'm running version 5.6.0b9.
     
  2. panbook

    panbook

    Joined:
    May 25, 2012
    Posts:
    16
    +1

    The same in our project.
    Error appeared after update to 5.6.0b9.
     
  3. cstlmode

    cstlmode

    Joined:
    Dec 2, 2014
    Posts:
    88
    i'm getting this too any possible solution for this
     
  4. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    I've got this problem in a perfectly working project after I upgraded to 5.6. Looks like I've got to install 5.5 again and pray my Collaborate backup isn't too outdated.
     
  5. cstlmode

    cstlmode

    Joined:
    Dec 2, 2014
    Posts:
    88
  6. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    By the way, I installed 5.5 in a new folder, opened my project in 5.5 and it works as it did before, so this is a bug in 5.6. To get around it, roll back to 5.5 until Unity fixes this.
     
  7. cstlmode

    cstlmode

    Joined:
    Dec 2, 2014
    Posts:
    88
    @DroidifyDevs yeah,i already have the project working fine on 5.5 , i upgraded to 5.6 cause i needed some new features , seams like i have to wait little bit more after all
    thanx
     
  8. WaylandGod

    WaylandGod

    Joined:
    Jul 23, 2015
    Posts:
    7
    I got a similar error when I upgrade to unity 5.6.0f3 recently. And I just solved this problem by enable Multithreaded Rendering.
     
  9. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    Unfortunately I've had this issue with multithreaded rendering enabled, I've toggled it off and on and tried playing with it both and on, but still same result. Currently waiting for Unity QA to reply to my reply to their response. For now, I'll sit tight on 5.5 and if Unity QA tells me a solution, I'll post it here as well.
     
  10. cstlmode

    cstlmode

    Joined:
    Dec 2, 2014
    Posts:
    88
    for me this was because i used gameObject.SetActive() inside OnBecameInvisible() OnBecameVisible() or OnWillRenderObject()
    i got over it by using this instead
    Code (JavaScript):
    1. function LateUpdate(){
    2.     if (GetComponent.<Renderer>().isVisible && Detected )   {
    3.         Detected=false;
    4.         MyGameObject.SetActive(true);
    5.     }
    6.     else if(!GetComponent.<Renderer>().isVisible && !Detected )  {
    7.         Detected=true;
    8.         MyGameObject.SetActive(false);
    9.     }
    10. }
    i got back to using 5.5 after all , the 5.6 is very unstable and not very good in term of performance compared to 5.5 ,
    i used to run my app on my phone with 60 -50 fps ,it went down to bellow 30 with 5.6 , so annoying !!
     
    GilbertoBitt likes this.
  11. GilbertoBitt

    GilbertoBitt

    Joined:
    May 27, 2013
    Posts:
    76
    @cstlmode i fix mine putting a invoke inside OnBecomeVisible the invoke call the method that has the .SetActive inside! my invoke has delay the activa in 0.1f after OnBecomeVisible!

    Code (CSharp):
    1. void OnBecameVisible() {
    2.         Invoke("startPlataform", 0.1f);
    3. }
    4.  
    5. void SetActive() {
    6.         yourObject.SetActive(true);
    7. }
     
    cstlmode likes this.
  12. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    2 things about that:

    1: That is ridiculously expensive to do, especially on hundreds of objects on mobile in my case. While it's a workaround, it will be a very significant performance drop.

    2: That still doesn't help me. I completely disabled the script I was using to animate my spawned prefabs (which also used OnBecameVisible) and that didn't help at all. However, when I moved my game camera so it wouldn't look at my spawned prefabs, and then panned the Editor camera to look at them, I noticed that the errors would come only when the editor camera was looking at where the soldiers were supposed to be spawned.

    That's all hard to explain with text, so here are the soldiers working perfectly in 5.5:


    And this is what happens in 5.6. Note that I've removed all scripts on the spawned soldiers, so that there's no OnBecameVisible called from my code:


    So I'm baffled, but apparently OnBecameVisible is bugged in 5.6, so once Unity fixes that bug my issue should go away.
     
  13. cstlmode

    cstlmode

    Joined:
    Dec 2, 2014
    Posts:
    88
    @DroidifyDevs i know that it's expensive but it's just temporary solution to keep things going until unity sort this out , you can try @GilbertoBitt solution it's less expensive i guess ,but i havn't tried it my self ,
    regarding why it didn't work for you , i guess disabling the script is not enough try to comment the OnBecameVisible OnBecameInvisible part in your script and run it, if the error persist then there must be something else causing it
     
  14. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    Thanks for the ideas. I did comment the code AND remove the components.

    Also, using Invoke as @GilbertoBitt stated is just impossible for me. In a nutshell, I have dozens of animated soldiers on mobile. Skinned mesh renderers are very expensive, so to lighten the load, I first converted the animations to 30 static meshes. Then I have a script that cycles through those meshes to give the static meshes the illusion that they are animations. In the same script I was using OnBecameVisible to further optimize by not running the script needlessly if we can't see the animations. Using Invoke to wait 0.1 seconds would make the animations run at less than 10FPS which is horrible.

    Here's the script so you can be sure that I've commented out OnBecameVisible:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CharachterAnimator : MonoBehaviour {
    6.  
    7.     //just to show in the Editor
    8.     public GameObject PlaceHolder;
    9.     public Transform WalkFramesParent;
    10.     public float TimeBetweenWalkFrames;
    11.     public Transform AttackFramesParent;
    12.     public float TimeBetweenAttackFrames;
    13.     public Transform DieFallFramesParent;
    14.     public float TimeBetweenDieFallFrames;
    15.     //private List<Transform> WalkFrames;
    16.     private List<Transform> WalkFrames = new List<Transform>();
    17.     private List<Transform> AttackFrames = new List<Transform>();
    18.     private List<Transform> DieFallFrames = new List<Transform>();
    19.     private List<Transform> CurrentFrames;
    20.     private int CurrentFramesLength;
    21.     private int WalkFramesLength;
    22.     private int AttackFramesLength;
    23.     private int DieFallFramesLength;
    24.     //just like regular animation state, assign an int for animation type
    25.     public int StaticFrameAnimationState;
    26.     public int CurrentFrame;
    27.     public float TimeBetweenFrames;
    28.     public bool DieAnimationPlayed;
    29.     public bool IsVisible;
    30.     //use to restore animation when pausing
    31.     private int PreviousStaticFrameAnimationState;
    32.     // Use this for initialization
    33.     void Start ()
    34.     {
    35.         PlaceHolder.SetActive(false);
    36.        
    37.         foreach (Transform child in WalkFramesParent)
    38.         {
    39.             WalkFrames.Add(child);
    40.             WalkFramesLength++;
    41.         }
    42.         foreach (Transform child in AttackFramesParent)
    43.         {
    44.             AttackFrames.Add(child);
    45.             AttackFramesLength++;
    46.         }
    47.         foreach (Transform child in DieFallFramesParent)
    48.         {
    49.             DieFallFrames.Add(child);
    50.             DieFallFramesLength++;
    51.         }
    52.         GetAnimationType();
    53.         StartCoroutine(GoToFrame());
    54.     }
    55.  
    56.     //void OnBecameInvisible()
    57.     //{
    58.     //    IsVisible = false;
    59.     //    //save animation state to use when visible again
    60.     //    PreviousStaticFrameAnimationState = StaticFrameAnimationState;
    61.     //    StaticFrameAnimationState = 0;
    62.     //    Debug.Log("Invisible");
    63.     //}
    64.  
    65.     //void OnBecameVisible()
    66.     //{
    67.     //    IsVisible = true;
    68.     //    StaticFrameAnimationState = PreviousStaticFrameAnimationState;
    69.     //    Debug.Log("Visible");
    70.     //}
    71.  
    72.     //void LateUpdate()
    73.     //{
    74.     //    if (CurrentFrames[CurrentFrame].gameObject.GetComponent<Renderer>().isVisible)
    75.     //    {
    76.     //        IsVisible = true;
    77.     //        //    StaticFrameAnimationState = PreviousStaticFrameAnimationState;
    78.     //        //    Debug.Log("Visible");
    79.     //    }
    80.  
    81.     //    else
    82.     //    {
    83.     //        IsVisible = false;
    84.     //        //    //save animation state to use when visible again
    85.     //        //    PreviousStaticFrameAnimationState = StaticFrameAnimationState;
    86.     //        //    StaticFrameAnimationState = 0;
    87.     //        //    Debug.Log("Invisible");
    88.     //    }
    89.     //}
    90.  
    91.     IEnumerator GoToFrame()
    92.     {
    93.         //var wait = new WaitForSeconds(TimeBetweenFrames);
    94.         while (true)
    95.         {
    96.             CurrentFrames[CurrentFrame].gameObject.SetActive(true);
    97.             yield return new WaitForSeconds(TimeBetweenFrames);
    98.             CurrentFrames[CurrentFrame].gameObject.SetActive(false);
    99.             //if not idle
    100.             if (StaticFrameAnimationState != 0)
    101.             {
    102.                 CurrentFrame++;
    103.             }
    104.             if (CurrentFrame < CurrentFramesLength)
    105.             {
    106.                 CurrentFrames[CurrentFrame].gameObject.SetActive(true);
    107.             }
    108.  
    109.             else
    110.             {
    111.                 GetAnimationType();
    112.             }
    113.         }
    114.     }
    115.    
    116.     void GetAnimationType()
    117.     {
    118.         //all frames in this group done, either loop or switch to another animation type!
    119.  
    120.         if (StaticFrameAnimationState == 0)
    121.         {
    122.             CurrentFrame = 0;
    123.             PlaceHolder.SetActive(true);
    124.             CurrentFrames[CurrentFrame] = PlaceHolder.transform; //FIX THIS ERORR
    125.             TimeBetweenFrames = 0.6f;
    126.             return;
    127.         }
    128.  
    129.         if (StaticFrameAnimationState == 1)
    130.         {
    131.             CurrentFrame = 0;
    132.             TimeBetweenFrames = TimeBetweenWalkFrames;
    133.             CurrentFrames = WalkFrames;
    134.             CurrentFramesLength = WalkFramesLength;
    135.             CurrentFrames[0].gameObject.SetActive(true);
    136.             return;
    137.         }
    138.  
    139.         if (StaticFrameAnimationState == 2)
    140.         {
    141.             CurrentFrame = 0;
    142.             TimeBetweenFrames = TimeBetweenAttackFrames;
    143.             CurrentFrames = AttackFrames;
    144.             CurrentFramesLength = AttackFramesLength;
    145.             CurrentFrames[0].gameObject.SetActive(true);
    146.             return;
    147.         }
    148.  
    149.         if (StaticFrameAnimationState == 3)
    150.         {
    151.             //don't play die animation more than once
    152.             if (DieAnimationPlayed == false)
    153.             {
    154.                 CurrentFrame = 0;
    155.                 TimeBetweenFrames = TimeBetweenDieFallFrames;
    156.                 CurrentFrames = DieFallFrames;
    157.                 CurrentFramesLength = DieFallFramesLength;
    158.                 CurrentFrames[0].gameObject.SetActive(true);
    159.                 DieAnimationPlayed = true;
    160.                 return;
    161.             }
    162.  
    163.             else
    164.             {
    165.                 //destroy the controller script when soldier dies, no need to animate a corpse ;)
    166.                 CurrentFrames[DieFallFramesLength - 1].gameObject.SetActive(true);
    167.                 Destroy(this.gameObject.GetComponent<CharachterAnimator>());
    168.                 return;
    169.             }
    170.         }
    171.         Debug.Log("Invalid input");
    172.     }
    173. }
    174.  
    At this point I'm waiting for OnBecameVisible to be fixed so I can go to 5.6, and I'm glad you found workarounds that work for you!
     
  15. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    487
  16. batalhadematos

    batalhadematos

    Joined:
    Apr 21, 2017
    Posts:
    2
    WaylandGod,

    Can you tell me how to enable Multithreaded Rendering? I am also facing the same problem.

    Thank you
     
  17. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    File > Build Settings > Player Settings > Other Settings. But that didn't help me.
     
  18. batalhadematos

    batalhadematos

    Joined:
    Apr 21, 2017
    Posts:
    2
    Thank you DroidifyDevs,

    I was expecting to solve my problem with this solution and no luck also.

    This is frustating... new to Unity and found this problem on first test game.

    Will wait for a solution.

    Thank you anyway

    Best regards

    Paulo
     
  19. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    As an update, this is what the QA team wrote to me:

    Hi,

    This was an intentional change and has been backported also to 5.5 (and probably 5.4). Adding renderers during onPreRender can cause invalid internal state and lead to crashes. This won't always happen and is an internal race condition. We have explicitly disallowed this on purpose.


    I replied, asking how to get around this change, but got no response :(
     
  20. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Hi

    Just wanted to add I am starting to investigate and work on this bug report.
    As the QA reply said there were valid reasons to add the code to disable adding/removing renderers during OnPreRender.

    Feel free to reply or Direct Message me if you have more questions to see how I can help and to explain more about the change and the rationale for it.

    One suggestion to work within this *new* restriction is a bit like the Invoke with a delay solution but instead defer the enabling/disabling of the renderer's to the main update function. By this I mean in your current callbacks instead of enabling/disabling the GameObject, add the request to a list and process that list in the next Update() call. I need to explain the above suggestion is just an idea (based on previous experiences) and I need to try it out in the examples given to see how appropriate it is.
     
  21. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    425
    For me it is happening with disabling and enabling gameobjects in an animation and I don't have any scripts controlling them otherwise. It happens right when the camera is enabled on an animated object that has skinnedmeshrenderer gameobjects being enabled and disabled. So is there a workaround for that? Otherwise changing hundreds of animations is out of the question for me.
     
    NikaSeed likes this.
  22. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Hi all,

    I wanted to give a progress update. I am being very open and don't like to give updates until a solution is known.

    The code for showing the error about adding a Renderer during the scene callbacks e.g. OnPreRender is in 5.6 and it is backported to 5.5 and 5.4.

    The difference in 5.6 comes from an unintentional side-effect of an optimisation in 5.6. When a Renderer is added to the scene from instantiating a GameObject e.g. Prefab it is now added immediately to the scene. Before 5.6 the Renderer being added to the scene was deferred until the next frame Update() which is a safe time to add a new Renderer to the scene.

    We are discussing this issue and working to find a solution. If we find a solution it should be backported to 5.6 i.e. a patch release.

    If you are suffering from these error messages after upgrading to 5.6 then all I can suggest is until we find the fix and it is backported to 5.6 and released then do not upgrade to 5.6 and stay on 5.5.

    Thanks

    Jake
     
    playemgames and DroidifyDevs like this.
  23. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Hi

    Bit of a progress update. I am working on a prototype code fix for this problem. The progress is good and I am testing it with different reproduction cases. There are quite a few different reproductions to test and make sure they still work.

    Thanks

    Jake
     
    playemgames and DroidifyDevs like this.
  24. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    425
    Let me know if you need another sample project, I can see if I can come up with something for you if needed.
     
  25. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Hi

    Apologies for a long delay (meetings and travelling getting in the way but travelling time is great for debugging).

    I have investigated the one difference I was seeing between 5.5 & 5.6 (after applying the fix for adding renderers) and the change is a difference in the animation code (not related to the new code to fix adding renderers). I will chase up with the animation team to discuss this behaviour difference to double check it is intentional.

    This means the prototype code I have is verified on all the test cases I have. I am now working on the automated tests for it and exploring/stressing potential edge case scenarios to make sure they are handled correctly.

    I welcome any more reproduction projects please direct message me if you have any more projects I can test with.

    I am hoping to make a 5.6 based feedback build next week which I can share directly with anyone who is willing to try it out and give feedback.

    Thanks

    Jake
     
    playemgames likes this.
  26. cstlmode

    cstlmode

    Joined:
    Dec 2, 2014
    Posts:
    88
    hello Jake ,
    thank you for your effort on fixing this issue, i rolled back to 5.5 just because of it , i wish i could have my hand on 5.6 as soon as possible ,
    i've checked the download section on road map , seams like the unity team have released the 5.6.1 yesterday , is the issue sorted in that version or not yet ?
     
  27. cstlmode

    cstlmode

    Joined:
    Dec 2, 2014
    Posts:
    88
    hey guys i tried the new 5.6.1 today, the problem still persist ,
     
  28. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    425
    Any more news, looks like it didn't make it into patch 5.6.1p1.
     
  29. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    I guess at this point we're waiting for @JakeTurner to share an experimental build, until then since this is a Unity issue there's not much we can do :(
     
  30. Nabren

    Nabren

    Joined:
    Mar 7, 2014
    Posts:
    61
    Basically. Really hoping to upgrade to Unity 5.6 soon, but this is definitely a blocker.
     
  31. Jromano0

    Jromano0

    Joined:
    Nov 9, 2015
    Posts:
    8
    I had the same problem. I am using Unity 5.6.0p1 and upgade today to 5.6.1.p1 and the problem persists.
    For me, the problem occurs when I am Enabling a item (like a bag, celular, etc) that is a acessory of my avatar and is a child object of my avatar object. For me this workaround solved the problem:
    First I do:
    avatar.SetActivate(false);
    # then I enable the item:
    item.SetActivate(true);
    # then turn activate the avatar:
    avatar.Setactivate(true);
     
  32. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Sorry for the delay. I have been working on the automated tests and exploring edge cases i.e. Add Renderer during OnPreRender and then instantly call DestroyImmediate() on it.

    The automated tests are all passing now and the reproduction cases I have are also working.

    The code is now going through code review and automated testing on the build farm. I can start making a 5.6 feedback build when the automated testing on the build farm is green which I am hoping to be sometime this weekend.
     
  33. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Can you give me a simple reproduction project, so I can verify it is fixed by my changes. My changes should only make a difference to any script code running during OnPreRender, OnWillRenderObject, OnBecameVisible, OnBecameInvisible.
     
  34. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Hi

    Sorry again for the delay. I was away at hackweek last week and the 5.6 version of the fix didn't instantly work (not a problem in the code, just some minor differences between 5.6 and the latest Unity version).

    I am now working to get a 5.6.1 based feedback build prepared. It should hopefully be ready within a couple of days.

    Thanks

    Jake
     
  35. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Hi

    I have a feedback build based on 5.6.1 ready. Please send me a direct message (conversation) if you would like to try it out.

    Thanks

    Jake
     
  36. Chromega1231

    Chromega1231

    Joined:
    Jan 25, 2015
    Posts:
    9
    I'm getting this without any calls to OnBecameVisible or OnBecameInvisible, and my only OnPreRender call is a seemingly harmless render texture adjustment. But I'm getting this error since upgrading to 5.6.1p2 (was on 5.5.1p3 previously). It seems to be caused by an animation component (old style Animation, not Animator) with its culling type set to "Based On Renderers". Indeed, the animation that gets played hides and shows some child game objects. Does that sound like a case accounted for in this fix? If not, I can try to work around.
     
  37. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    Maybe. Send a PM to JakeTurner so he can hook you up with the beta build that worked for me.
     
  38. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Good news the fix just landed in the main trunk of the Unity source code and is now on its way back to a Unity patch release. I do not know which Unity patch release it will be yet but it should not take too long.
     
    playemgames likes this.
  39. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Quick update: The fix is moving fast through the branches and scheduled for the next 5.6.2 patch release. I can't confirm that until it actually happens. The internal testing is still ongoing.

    I wanted to say "Thank You" to all the people on this thread who:
    a) reported the problem with simple and clear reproduction projects (of all the different sources)
    b) were patient waiting for the fix to be ready to be tested
    c) helped to test and verify the fix before it is released.

    All three of those steps really help to get the fix made, verified. Verification by users on user project really helps to grease the wheels of the internal Unity machine compared to say just internal testing.
     
    edupo, DroidifyDevs and playemgames like this.
  40. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,661
    Now if only we could grease the wheels on nested prefabs and a new Terrain system... :D
     
  41. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    425
    Looks like it is all patched up in 5.6.2p1 thanks again for all the help @JakeTurner !
     
  42. armnotstrong

    armnotstrong

    Joined:
    Mar 3, 2017
    Posts:
    18
    Hey, I run into the same issue, does the patch released? which patch should I get? 5.6.2p1? And I also want to know if a patch with greater version contains all the previous fix?
     
  43. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    It is in 5.6.2p1 - from the release notes
    • (897994, 907626, 901242) - Graphics: Fixed error message "Enabling or adding a Renderer during rendering; this is not allowed." when creating or enabling a game object during OnPreRender, OnWIllRenderObject, OnBecameVisible, OnBecameInvisible callbacks
     
  44. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    133
    Yes the patch releases within a Unity version are cumulative i.e. they contain all previous fixes.
     
    cstlmode likes this.
  45. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    540
    Same issue after upgrading to 5.6. As this is for teaching purposes, I feel better with a solution that works on all Unity versions. stonePrefab is a sprite prefab.
    A code patch for the problem is:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class StoneSpawner : MonoBehaviour {
    5.  
    6.     public GameObject stonePrefab; // The stone prefab we want to spawn from here
    7.  
    8.     // This standard event method will be called whenever this object is rendered
    9.     IEnumerator OnBecameVisible () {
    10.         yield return new WaitForEndOfFrame();
    11.         Instantiate(stonePrefab, transform.position, Quaternion.identity);
    12.     }
    13.  
    14. }
    15.  
     
  46. edupo

    edupo

    Joined:
    Sep 11, 2017
    Posts:
    1
    I just run into this problem and was fixed after updating... Just wanted to say: Great job guys!