Duplicate immediate mode rendering when creating objects at runtime

Avatar
  • updated
  • Fixed

While creating objects at runtime that contains an immediate mode rendering script, I get duplicate rendering for as many objects as I have (i.e. if I add 5 objects at runtime, I'll end up with each object being rendered 5 times, so it will be 25 renders total).

Steps:

1. Create a new project using Unity 2021.1.15f1 and URP

2. To simplify things, create an empty scene, add a Camera at [0, 0, -2]

3. Create an empty GameObject and add the following script:


using System.Collections;
using System.Collections.Generic;
using Shapes;
using UnityEngine;
using ScaleMode = Shapes.ScaleMode;

public class ShapesTest : ImmediateModeShapeDrawer {
[SerializeField]
private float dotRadius = 4.0f;

[SerializeField]
private float innerRadius = 8.0f;
[SerializeField]
private float innerThickness = 2.0f;

[SerializeField]
private float outerRadius = 12.0f;
[SerializeField]
private float outerThickness = 2.0f;

public Color color = Color.magenta;

public override void DrawShapes(Camera cam) {
using (Draw.Command(cam)) {
Draw.ResetAllDrawStates();
Draw.BlendMode = ShapesBlendMode.Additive;
Draw.Thickness = innerThickness;
Draw.LineGeometry = LineGeometry.Flat2D;
Draw.SizeSpace = ThicknessSpace.Pixels;
Draw.ThicknessSpace = ThicknessSpace.Pixels;
Draw.RadiusSpace = ThicknessSpace.Pixels;
Draw.Position = transform.position;
Draw.ScaleMode = ScaleMode.Uniform;
Draw.Color = color;

Draw.Disc(Vector3.zero, Quaternion.identity, dotRadius);

Draw.Ring(Vector3.zero, Quaternion.identity, innerRadius);

Draw.Thickness = outerThickness;

Draw.Ring(Vector3.zero, Quaternion.identity, outerRadius);
}
}
}


4. Run the scene

5. While running, clone the object with the script 4 times (or just create a new one and attach the script, cloning the object is not the issue as far as I can see)

6. Run the Frame debugger, and check Shapes command, you should see the object being rendered 25 times instead of the expected 5

Reporting a bug? please specify Unity version:
2021.1.15f1
Reporting a bug? please specify Shapes version:
4.0.2
Reporting a bug? please specify Render Pipeline:
URP
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Fixed

managed to reproduce it when using the latest release, but it doesn't happen anymore in my internal dev branch, so it looks like this has been accidentally fixed due to another issue :)

there was a major issue I found that this likely was caused by, even though the fix was intended for something else

Avatar
Freya Holmér creator
  • Under Review

it looks fine on my end, where do you see the 25 calls?

Avatar
Edu Garcia

That's certainly odd, as I tried with a completely new project just in case. You're creating those clones while the game is running, and not before, right?

Other than that I have no more steps to do, it happens every time for me. I can share the project if it helps, but it's as barebones as described.

Avatar
Freya Holmér creator

yeah, created one before pressing play, cloned the rest at runtime

Avatar
Edu Garcia

Ok, a bit more info I found while trying to automate this to share a project as complete as possible.

I created a script that clones those objects when you run the scene, but the issue doesn't show up if you run the script immediately. But if I add a small delay (of a second for example) then the issue showed up. This is basically the same as creating them by hand as I'm assuming you did, so maybe it doesn't help much 🙂. Another thing is that I'm using a Mac.

In any case I'll try sharing a project soon, my internet is just really bad at the moment, so it takes forever.

Avatar
Edu Garcia

Ok, I've reduced the project as much as I can, it's only missing Shapes itself on the root of Assets. URL is we.tl/t-RqDAJRp41r . Please let me know if I can provide anything else, and thanks again.

Avatar
Freya Holmér creator
  • Answer
  • Fixed

managed to reproduce it when using the latest release, but it doesn't happen anymore in my internal dev branch, so it looks like this has been accidentally fixed due to another issue :)

there was a major issue I found that this likely was caused by, even though the fix was intended for something else

Avatar
Edu Garcia

Awesome, many thanks, and sorry for all the trouble 🙂