Editing class properties in different places in the editor

When developing with Unreal, it is common for programmers to implement properties on Actors or other objects in C++, and make them visible to the editor for designer use. However, sometimes it makes sense to view a property, or to make it editable, but only on the object's default state. Sometimes the property should only be modifiable at runtime with the default specified in C++. Fortunately, there are some specifiers that can help us restrict when a property is available.

How to do it…

  1. Create a new Actor class in the editor called PropertySpecifierActor.
  2. Add the following property definitions to the class:
    UPROPERTY(EditDefaultsOnly)
    bool EditDefaultsOnly;
    UPROPERTY(EditInstanceOnly)
    bool EditInstanceOnly;
    UPROPERTY(EditAnywhere)
    bool EditAnywhere;
    UPROPERTY(VisibleDefaultsOnly)
    bool VisibleDefaultsOnly;
    UPROPERTY(VisibleInstanceOnly)
    bool VisibleInstanceOnly;
    UPROPERTY(VisibleAnywhere)
    bool VisibleAnywhere;
  3. Compile your code and launch the editor.
  4. Create a new blueprint based on the class.
  5. Open the blueprint, and look at the Class Defaults section.
    How to do it…
  6. Note which properties are editable and visible.
    How to do it…
  7. Place instances in the level, and view their Details panels.
    How to do it…
  8. Note that a different set of properties are editable.

How it works…

  1. When specifying UPROPERTY, we can indicate where we want that value to be available inside the Unreal editor.
  2. Visible* prefixes indicate that the value is viewable in the Details panel for the indicated object. The value won't be editable, however.
  3. This doesn't mean that the variable is a const qualifier; however, native code can change the value, for instance.
  4. Edit* prefixes indicate that the property can be altered within the Details panels inside the editor.
  5. InstanceOnly as a suffix indicates that the property will only be displayed in the Details panels for instances of your class that have been placed into the game. They won't be visible in the Class Defaults section of the Blueprint editor, for example.
  6. DefaultsOnly is the inverse of InstanceOnlyUPROPERTY will only display in the Class Defaults section, and can't be viewed on individual instances within the level.
  7. The suffix Anywhere is the combination of the two previous suffixes—the UPROPERTY will be visible in all Details panels that inspect either the object's defaults or a particular instance in the level.

See also

  • This recipe makes the property in question visible in the inspector, but doesn't allow the property to be referenced in the actual Blueprint Event Graph. See the next recipe for a description of how to make that possible.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.155.49