Skip to content
This repository has been archived by the owner on Aug 22, 2018. It is now read-only.

Check [NotNull] in the game studio #662

Open
stefnotch opened this issue Apr 5, 2018 · 2 comments
Open

Check [NotNull] in the game studio #662

stefnotch opened this issue Apr 5, 2018 · 2 comments

Comments

@stefnotch
Copy link

The use case would be making sure that every entity has all required components. For example, a player controller component (move the player with the keyboard) needs a camera.

public class PlayerControllerComponent: SyncScript
{
    //Game Studio doesn't seem to check this, which makes it rather useless
    [NotNull]
    public CameraComponent Camera { get; set; }
}

Though, only public properties which can be edited in the game studio should be checked.

@Kryptos-FR
Copy link

That is not the purpose of NotNull. It is a design-time only attribute used to let ReSharper do a static analysis to detect wrong usages of nullability.

See: https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html

@stefnotch
Copy link
Author

@Kryptos-FR Oh, I assumed that it didn't have anything to do with that [NotNull] attribute, since it's defined inside SiliconStudio.Core.Annotations.

Well, what would be an alternative to achieve what I want to achieve? It's not that uncommon that a component needs a reference to another component to work properly.

Checking it in code would require me to write a lot of extra code that I would prefer to avoid writing. Also, it would be a runtime check rather than a game-studio-time check.

Dependency injection would be one alternative that I can think of right now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants