Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    Public properties and fields

    Beginner Programmer

    When you declare a public property or field in a script, the property becomes accessible in Game Studio from the script component properties.

    Property in Game Studio

    You can attach the same script to multiple entities and set different property values on each entity.

    Note

    Public properties or fields must be serializable to be used in Game Studio.

    Add a public property or field

    This script has a public property (DelayTimeOut):

    public class SampleSyncScript : StartupScript
    {
        // This public member will appear in Game Studio
        public float DelayTimeOut { get; set; }
    }
    

    Game Studio shows the DelayTimeOut property in the script component properties:

    Public property appears in the Property Grid

    Note

    As a general rule, if you want to display the property or field in Game Studio, getters and setters should do as little as possible. For example, they shouldn't try to call methods or access Stride runtime API.

    For example, the following code will create problems, as it tries to access Entity.Components, which is only available at runtime:

    public class SampleSyncScript : StartupScript
    {
      private float delayTimeOut;
      // This public member will appear in Game Studio
      public float DelayTimeOut
      {
          get { return delayTimeOut; }
          set
          { 
              delayTimeOut = value;
              Entity.Components.Add(new SkyboxComponent());
          }
      }
    }
    

    If you want to include code like this in a property or field, hide it so Game Studio doesn't display it (see below).

    Hide properties or fields in the Property Grid

    If you don't want Game Studio to show a property in the Property Grid, you can:

    • declare your member internal or private, or
    • use the DataMemberIgnore attribute like this:
    
        // This public property isn't available in Game Studio
        [DataMemberIgnore]
        public float DelayTimeOut { get; set; }
    

    Game Studio no longer shows the property:

    Public property been hidden with ```[DataMemberIgnore]```

    See also

    • Types of script
    • Create a script
    • Use a script
    • Scheduling and priorities
    • Events
    • Debugging
    • Preprocessor variables
    • Improve this Doc
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation