UActorComponent::GetComponentInstanceData
#include "Components/ActorComponent.h"
Access: public
Specifiers: virtualconst
Description
Called before construction scripts are rerun to capture any component state that should survive the component being destroyed and recreated. Override to preserve custom data across RerunConstructionScripts.
Caveats & Gotchas
- • This is only called for components being destroyed by a construction script rerun (e.g., Blueprint SCS components). Native (C++) components are never destroyed by construction script reruns and never have this called.
- • The returned data must match the type expected by ApplyToComponent. If you override GetComponentInstanceData, you must also override ApplyToComponent on your FActorComponentInstanceData subclass, otherwise the cached data is silently discarded.
Signature
ENGINE_API virtual TStructOnScope<FActorComponentInstanceData> GetComponentInstanceData() const Return Type
TStructOnScope<FActorComponentInstanceData> Example
Override to preserve runtime state across construction reruns C++
// In header: FMyComponentInstanceData : public FActorComponentInstanceData
// (with your custom fields)
TStructOnScope<FActorComponentInstanceData> UMyComponent::GetComponentInstanceData() const
{
TStructOnScope<FActorComponentInstanceData> Data = MakeStructOnScope<FActorComponentInstanceData, FMyComponentInstanceData>(this);
FMyComponentInstanceData* MyData = Data.GetPtr<FMyComponentInstanceData>();
MyData->SavedRuntimeState = CurrentRuntimeState;
return Data;
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?