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
  • Static Variables in UnrealSharp
  • Available classes that manages static data
  1. Documentation

Static Variables

PreviousTrace ChannelsNextFWorldStaticVar<T>

Last updated 5 months ago

Managing static variables in Unreal Engine can be tricky. Regular static variables have a global lifetime, meaning their values persist across the entire application runtime. While this may seem convenient, it can lead to issues.

For instance, if you use regular static variables to store world-specific data, you might encounter problems such as:

  • Memory Leaks: Static variables won’t automatically release their references when a UWorld is destroyed, potentially causing garbage collection (GC) issues.

  • Global Scope Conflicts: Since regular static variables are shared across all worlds, their values are prone to accidental overwrites or unintended usage.

Static Variables in UnrealSharp

To enable these classes in your project you need to include this in your csproj:

<Reference Include="UnrealSharp.StaticVars">
  <HintPath>..\..\Plugins\UnrealSharp\Binaries\Managed\UnrealSharp.StaticVars.dll</HintPath>
</Reference>

Available classes that manages static data

FGameStaticVar<T>
FWorldStaticVar<T>