Hi, We’ve discovered a crash in cook: [Image Removed]
In the following scenario: ComponentB(ULightBoxComponent) is created as a subobject within ComponentA(ULocalLightComponent), and ComponentB requires serialization, cook will crash:
[Image Removed]. We k
[Image Removed]
After some investigation, we found this is relateted to FActorComponentInstanceData::ApplyToComponent, the DuplicatedObject(ComponentB) is executing : OtherObject->Rename(nullptr, GetTransientPackage(), REN_DontCreateRedirectors);
[Image Removed]
and rename function would lead to remove component without calling unregister
We know that we should avoid using this way as much as possible, but is there any fix? What is ComponentInstanceDataCache’s DuplicatedObject designed for?
Thanks for the detailed steps. I’ve been able to reproduce the issue, and I’m currently checking whether it has been fixed in the development version of the engine. I’ll get back to you once I’ve tested it. If a fix already exists, we’ll upload the corresponding commit here so you can integrate it directly into your engine version. If it’s not yet fixed, we’ll raise a bug report to Epic so they can work on a solution.
ComponentInstanceDataCache is a class that caches data from component instances within Unreal. Its main purpose is to save and restore modified values of component and subobject instances. When a Blueprint is recompiled, the Construction Script runs, or during a cook, the engine caches this information and restores any differences for each instance. Essentially, it’s a way to temporarily store and reapply instance data and properties.
It seems that in this case, the system is renaming the nested component to the transient package while it’s still registered in the world. It should unregister the component first.
As mentioned, I’ll check whether this has already been resolved in the latest versions.
Hey there, I asked around internally and confirmed that components creating component default subobjects (DSOs) isn’t supported. Only actors can construct component DSOs. Components can construct general UObject DSOs, there are some examples of that in engine code, but not nested components.
There was a task at some point - UE-161084 - to be more clear about that limitation. I’ll reopen discussions surrounding that, since it would have saved you some time.
Hey there, I don’t have an update on whether we’ll make it clearer in engine code that nested CreateDefaultSubobjects aren’t expected to work. But I’ll close the case, since you have gotten the info.
I have not been able to reproduce this with verion 5.7. I’ll keep checking this case today but for now that crash is not happening anymore. Will update today again with any new information. If it has been fixed we can find the fix commit so that you can integrate it directly into your engine if you desire.
One small question: I assume ULightBoxComponent is a UBoxComponent that derives from UActorComponent, right? In your code you’re registering an actor component inside another actor component, and that could be the main issue.
Actor components are meant to be created inside actors, and calling CreateDefaultSubobject from within another component can be risky. It likely means the new component gets the parent component as its Outer instead of the actor, creating a component-within-component lifetime relationship.
Is there any particular reason you can’t add your LightBoxComponent directly to the APointLight (or even to ALight)? Making it a subobject of the light actor instead might solve the crash.
“I assume ULightBoxComponent is a UBoxComponent that derives from UActorComponent” - yes.
We can do this by creating component in actor to avoid this problem. But we just want to see whether creating from component is supported or not. If it’s too complicated to fix, just ignore it.
I don’t think it is supported, and not the intented way actor components are meant to be used, but there might be a workaround I might not be aware. I’ll escalate this directly to epic so they can give you a complete answer.