Section 6: Couldn't we use the [RequireComponent] attribute here?

Is there a reason later on as to why we don’t implement [RequireComponent(typeof(SavingSystem))] in the SavingWrapper class? It seems like it would make the system easier to implement and reduce the risk of having a SavingWrapper without a SavingSystem.

Or is there something I am missing cause it seems to me that the SavingWrapper class is going to be tightly dependent upon the functionality of the SavingSystem class so it seems like best practice to add the line as a fail safe.

It’s actually a good idea to use [RequireComponent] on the SavingWrapper. Bear in mind that if you add the tag after the SavingWrapper has been added to a GameObject, it will have no effect. Since we’re only creating the pair in one place (the PersistentObjectsPrefab), it’s not critical that we have the tag, but I would consider it a best practice.
Other places I would use the tag is in Fighter (requires Mover and Health to operate) and Experience (requires BaseStats to be effective).

2 Likes

Cool Thanks for the reply.

Privacy & Terms