-
Notifications
You must be signed in to change notification settings - Fork 855
XPipeline- Fix contextual menu Remove Component for lights and cameras #5431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XPipeline- Fix contextual menu Remove Component for lights and cameras #5431
Conversation
Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed. HDRP URP SRP Core Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I'd like to hear Rémi's thoughts on the attribute usage though. Also please check if the interface I mentioned could be removed/obsoleted.
|
||
/// <summary> | ||
/// Attribute to specify that a class is additional data of another component | ||
/// Currently is being used for HDRP/URP additional Camera and Light data | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class AdditionalComponentData : Attribute | ||
{ | ||
/// <summary> | ||
/// Summary the component type of is additional data | ||
/// </summary> | ||
public Type componentType; | ||
|
||
/// <summary> | ||
/// Constructor of the attribute | ||
/// </summary> | ||
/// <param name="componentType">The component type</param> | ||
public AdditionalComponentData(Type componentType) | ||
{ | ||
this.componentType = componentType; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm interested to hear what @RSlysz you think about this, in light of possible future work on additionaldata refactor. Currently AFAIK there's no IAdditionalComponentData
interface or similar, so this attribute now allows us to detect these components in SRP Core code. If there's already a plan to introduce this interface, then this attribute might be redundant. But even if so, it probably doesn't really hurt to add the attribute. So I'm fine with this, just wanted to raise this point :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't really need them as we previously considered that this was an editor workflow to manage. So we ended with having interface but on Editor side (such IRemoveAdditionalDataContextualMenu<Camera>
).
And the plan was to remove the additional data sibling component. So when we will be able to finish & land this, the attribute introduced here (or the former interface) will don't have any usage. That is why even if the need for it increased last year, I didn't add it as it add a public API that should be deprecated soon. :)
Now as the additional data refactor is just so overwhelming and it is a nightmare to know exactly when this will be finished, I'm ok with this introduction. But as it is public API, some user can want to use it in their custom SRP with component that we have not think of yet. Should we ensure that if this happens, can we ensure our system will works in this case?
Also, HD have additional component for Reflection Probe too (regarding comments). There is no conflict as URP don't have additional data for this so there is also no contextual menu dispatcher. But I would prefer to unify our workflow and thus use this component also for HDReflectionProbe.
Also as we partly automate the concept of additional data here, as a user, I would expect to not have to write RemoveAdditionalComponent contextual menu command and such when I wrote my own SRP. But this seams tricky to automate...
Lastly, I wonder if this should inherite [RequireComponent(typeof(Camera))]
as it seams to me we always have this one when using the [AdditionalComponentData(typeof(Camera))]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have a look at the Reflection Probe and how to automate the context menu.
The RequierComponent is sealed, so we can not inherit from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we also discussed inheriting from RequireComponent, I wonder if we could make it non-sealed? I'm not sure if there's a good reason to keep it sealed.
{ | ||
IRemoveAdditionalDataContextualMenu<T> instance = (IRemoveAdditionalDataContextualMenu<T>)Activator.CreateInstance(type); | ||
instance.RemoveComponent(component, ComponentDependencies(component)); | ||
IRemoveAdditionalDataContextualMenu<T> instance = new RemoveAdditionalDataContextualMenu<T>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is IRemoveAdditionalDataContextualMenu
still needed for something? AFAICT it only has one implementation, which is now also in SRP Core, so it seems redundant. Seems like it should be marked obsolete as it no longer does anything for you even if you write a custom context menu that inherits from it (since FetchFirstCompatibleTypeUsingScriptableRenderPipelineExtension<IRemoveAdditionalDataContextualMenu<T>>()
was removed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will mark it as obsolete :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Though I wonder if we can do better when introducing this attribute (see comments)
|
||
/// <summary> | ||
/// Attribute to specify that a class is additional data of another component | ||
/// Currently is being used for HDRP/URP additional Camera and Light data | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class AdditionalComponentData : Attribute | ||
{ | ||
/// <summary> | ||
/// Summary the component type of is additional data | ||
/// </summary> | ||
public Type componentType; | ||
|
||
/// <summary> | ||
/// Constructor of the attribute | ||
/// </summary> | ||
/// <param name="componentType">The component type</param> | ||
public AdditionalComponentData(Type componentType) | ||
{ | ||
this.componentType = componentType; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't really need them as we previously considered that this was an editor workflow to manage. So we ended with having interface but on Editor side (such IRemoveAdditionalDataContextualMenu<Camera>
).
And the plan was to remove the additional data sibling component. So when we will be able to finish & land this, the attribute introduced here (or the former interface) will don't have any usage. That is why even if the need for it increased last year, I didn't add it as it add a public API that should be deprecated soon. :)
Now as the additional data refactor is just so overwhelming and it is a nightmare to know exactly when this will be finished, I'm ok with this introduction. But as it is public API, some user can want to use it in their custom SRP with component that we have not think of yet. Should we ensure that if this happens, can we ensure our system will works in this case?
Also, HD have additional component for Reflection Probe too (regarding comments). There is no conflict as URP don't have additional data for this so there is also no contextual menu dispatcher. But I would prefer to unify our workflow and thus use this component also for HDReflectionProbe.
Also as we partly automate the concept of additional data here, as a user, I would expect to not have to write RemoveAdditionalComponent contextual menu command and such when I wrote my own SRP. But this seams tricky to automate...
Lastly, I wonder if this should inherite [RequireComponent(typeof(Camera))]
as it seams to me we always have this one when using the [AdditionalComponentData(typeof(Camera))]
.
} | ||
|
||
[MenuItem("CONTEXT/HDAdditionalCameraData/Remove Component")] | ||
static void RemoveComponent(MenuCommand command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we unify names? On light it is RemoveAdditionalComponent
and on Camera it is RemoveComponent
return; | ||
|
||
var c = (Camera)target; | ||
if (!(target is Camera c) || c == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious: target is Camera c
if target is null, c is (Camera)null right? Then why do we need the null check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because is null on the c++ world, not in c# the is
operator is not overriden
@RSlysz, updates on the PR:
@arttu-peltonen , the RequiereComponent not being sealed, maybe I will tackle it in another PR. |
@Unity-Technologies/gfx-qa-hdrp
@Unity-Technologies/gfx-qa-urp
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have only one concern that is not directly related to your PR:
CoreUtils has a whole section of UNITY_EDITOR
functions, which is asking for trouble in my opinion.
This definitely needs a refactoring to move editor code into editor assemblies
0484780
to
acf4713
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HDRP side all good. Checked with Lights, Cameras, Probes with HDRP and URP additional data assigned.
- Deleting additional data component is correctly blocked
- Deleting main component also clears additional data, no errors in console
- Undo/Redo correctly recreates deleted components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
developer already tested this PR, approving without additional coverage
@alex-vazquez : I reverted the backport I have done due to this error on 21.2 18:31:52.686 Information] Compiler |
@sebastienlagarde : Sorry Seb, this PR needs to be merged before, I forgot the backport label :( #5547 |
Purpose of this PR
Fix https://fogbugz.unity3d.com/f/cases/1358990/
The Light Additional Data and Camera Additional Data were not being removed properly.
Testing status
Comments to reviewers
Adding the attribute to know that a component is additional data for another component.