I am scripting in C# a component that has a lot of custom previews implemented within a display pipeline (please refer to this thread). I noticed that when I instantiate this component multiple times, either by inputting multiple objects (from outside the component) or by simply copy-pasting it, the display pipeline is completely messed up. It seems impossible to preview more than one instance of the same script/gh component.
Here is the part where I define all the previews.
All the lists/variables are coming from public static fields, I am not using any private methods.
I do clear those lists/variables in RunScript, so the previews don’t accumulate once I change a variable outside the component. This surely explains why I can’t create multiple instances of the all thing, it will remember only the last one since it clears everything each time it runs.
However I still do not get why the same problem appears when I just copy-paste the component and change one of the inputs.
That’s to be sure that each object/list is appearing in the order i typed them. I decided to do that following this discussion. I guess it’s hacky and is maybe not the way the order of appearance should be managed, but it works. I followed your advice but it did not solve anything (and messed up the order of appearance).
That was a mistake. Changed it, but did nothing…
Sorry, I did not find a way to post formatted code so I thought a screenshot would be more insightful. I will send you a message with the whole thing.
you are only storing one “mesh” in your global “inputMesh” variable - remember that when item access is supplied, and you provide a list, the “RunScript” method executes multiple times, effectively overwriting the variable after each run. You can either provide list access and store a list, or simply populate a list instead of a single mesh reference. The native CustomPreview component does something like the following:
In SolveInstance (akin to runscript in a compiled GHA):
check if it’s the first time “solveInstance” is executing in a given run - if it is, clear the list holding all geometry
populate a List where PreviewObject is a struct containing a piece of geometry and a color
In DrawViewportWires / DrawViewportMeshes:
iterate over the list of PreviewObjects and draw each one