public override void Initialize(FObjectInitializer initializer) { base.Initialize(initializer); RootComponent = initializer.CreateDefaultSubobject <USceneComponent>(this, new FName("DummyRoot")); ScoreText = initializer.CreateDefaultSubobject <UTextRenderComponent>(this, new FName("ScoreText")); ScoreText.RelativeLocation = new FVector(320, 60, 0); ScoreText.RelativeRotation = new FRotator(90, 0, 0); ScoreText.RelativeScale3D = new FVector(4, 4, 4); ScoreText.AttachToComponent(RootComponent, FName.None, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, false); // Care needs to be taken when dealing with FText. In C++ FText lifetime is automatically managed via shared pointers. // Any FText which has a lifetime maintained by C# (FText.OwnsReference==true) needs to be destroyed manually. This can be // done via by calling 'Dispose()', or in a 'using' statement. If neither is used, the finalizer will do the clean up when // the C# GC runs. using (FText text = FText.FromString("Score: 0")) { ScoreText.SetText(text); // - text needs to be disposed as the lifetime is maintained by C# // - ScoreText.Text doesn't need to be disposed as the lifetime is maintained by native code Debug.Assert(text.OwnsReference && !ScoreText.Text.OwnsReference); } }