UnrealSharp
  • Home
  • FAQ
  • Getting Started
    • Setup
    • Your First Script
    • Debugging
    • Packaging
  • Documentation
    • Classes
      • Properties
        • C++ Functions As C# Properties
        • C++ Properties with Getters/Setters
      • Functions
        • Flags
        • MetaData
      • Default Actor Components
      • Helper Methods
    • Structs
    • Enums
    • Interfaces
    • Delegates
    • Collections
      • TArray
      • TNativeArray
      • TSet
      • TMap
    • Multiplayer
      • Replicated Properties
      • RPCs (Remote Procedure Calls)
      • Replicated UObjects
    • Primary Data Assets
      • Loading Primary Data Assets
    • Loading Soft References
    • Trace Channels
    • Static Variables
      • FWorldStaticVar<T>
      • FGameStaticVar<T>
    • Logging
    • Async
    • Gameplay Tags
      • Gameplay Tag Container
    • Extension / Mixin Methods
    • Subsystems
    • Module Lifecycle
  • Links
    • Github Repository
    • Roadmap
    • Discord
Powered by GitBook
On this page
  1. Documentation
  2. Static Variables

FWorldStaticVar<T>

FWorldStaticVar<T> is a class designed to manage static variables that are tied to the lifetime of a UWorld. This means the value is automatically cleaned up when the associated UWorld is destroyed, such as during level transitions.

Declaration and Usage

You can declare a world-static variable like this:

public static readonly FWorldStaticVar<float> MyStaticFloat = new();

To use it within your C# code:

public class AMyActor : AActor
{
    public static readonly FWorldStaticVar<float> MyStaticFloat = new();
    
    public AMyActor()
    {
        // Set the value to 70 in the current World
        MyStaticFloat.Value = 70;
    }
}
PreviousStatic VariablesNextFGameStaticVar<T>

Last updated 5 months ago