0
\$\begingroup\$

Context: I am currently making the menu for my game demo. It involoves "Raindrop"-Gameobjects (Sprites) being repositoned and recolored after a random amount of time. I do this by instantiating a predefined amount of Raindrops and manipulate them after said amount of time.

I am using Unity 2018.1.6f and, if possible, want to avoid switching to another version. If it is of relevance and requested, I can also post my sprite import settings.

Problem: Upon repositioning a sprite, it keeps being rendered at its old position AND the new position, making it appear as if a new instance was created

(this isn't the case as 1. the objects in the hierarchy view remain the same, and 2. the unwanted "multiple renderings" aren't shown in the scene view either, only in game view)

As seen below, there are 5 Raindrop objects in the hierarchy as well as in the scene view. In the game view however, there a lot more than 5 Raindrops are being rendered. The amount of rendered Raindrops increases each time a single one is repositioned.

enter image description here

Further notice: I had a fairly similar problem once where a bug in my code caused it tho delete all objects at once. The objects were deleted but kept on being rendered and even functioning as if nothing happened, save for the difference that all moving objects would be rendered like the cards in solitaire once the game is over (I do not know of a different way of describing it). None of the code above, except for the Exit() function of MenuEnvironment destroys any object. As you can see, the rainbow objects are only instantiated once, upon Setup(GameObject, GameObject) and being continuously manipulated in Unity's Update Loop.

\$\endgroup\$
  • \$\begingroup\$ It sounds like you might have disabled the colour clearing step in rendering your frame or render target — so colour pixel values from last frame stay in the image instead of being erased to start fresh. Can you show us the camera / render pipeline setup you're using to draw this scene? \$\endgroup\$ – DMGregory Mar 16 at 6:55
0
\$\begingroup\$

As user DMGregory Pointed out, the camera settings are what cause this problem to occur. The camera's clear flags option was set to "don't clear":

enter image description here

Setting this option to "solid color" (or whatever else is appropiate in your case) fixed the problem:

enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.