I am facing a problem that shouldn’t be this complicated.
I have an item that I want to break so I generated a geometry collection form it’s static mesh and added it to the blueprint and handle switching between the static mesh and geometry collection at component hit event and all works fine, now I have many items that all inherit from a parent and at begin i get a data table to set the item’s static mesh and different other properties and the problem I am facing is changing the rest collection in the geometry collection component at runtime, I can’t figure it out for the life of me.
is it even doable in blueprints?
when i drag off of Geometry Collection Component i can only find “get Rest Collection” i can’t set it, and dragging off of Rest Collection i can only find Geometry Source Array, i tried setting, clearing and adding to the Geometry Source Array but it gives me access none error because Geometry Source array is flagged as Editor-Only.
i also tried setting Chaos Geometry Collection Component itself to something else from a variable but when i play it stays as it’s default value and not the new variable.
i tried on the event graph and construction script with no results.
Any help or screenshots would be much appreciated.
GeometryCollectionComponent has a SetRestCollection function but does not expose it to blueprints.
Unfortunately, I think it needs to be handled in C++.
If you are using the source code version of UE, you only need to add a UFUNCTION macro to the SetRestCollection function in GeometryCollectionComponent.h.
If you are using the binary version, you will need to add a C++
class and create a function that assigns an asset reference to the RestCollection variable.
It seems this has changed. The function is available but does not change the RestCollection when called in Blueprints. Maybe this is a bug but its not easy to tell if some other condition(s) need to be met before calling SetRestCollection
Were you able to get it to work in Blueprint or only in c++?
I’m having an issue where I call to set the rest collection in BP my print string returns the correct asset name but I’m getting absolutely nothing when it should be adding the geometry collection and I’m a little confused is this “Set rest collection” just a bugged node
Set Rest Collection is actually crashing the editor for me when called in the construction script of my BP. Trying to switch out the Collection based on an enum and it crashes.
Here is the error:
Found a solution that worked for me. I will note that I am not using SetRestCollection inside the ConstructionScript but I am using it when I have rounds restart in my game mode.
SetCollisionEnabled(ECollisionEnabled::NoCollision);
FGeometryCollectionPhysicsProxy* TempPhysicsProxy = GetPhysicsProxy();
if (TempPhysicsProxy)
{
FPhysScene_Chaos* Scene = GetInnerChaosScene();
Scene->RemoveObject(TempPhysicsProxy);
InitializationState = ESimulationInitializationState::Unintialized;
ResetRepData();
}
SetRestCollection(RestCollection);
// Enables simulated physics
const TWeakObjectPtr<UPrimitiveComponent> PreviousOwnerComponent = BodyInstance.OwnerComponent;
{
BodyInstance.OwnerComponent = nullptr;
BodyInstance.SetInstanceSimulatePhysics(true);
BodyInstance.OwnerComponent = PreviousOwnerComponent;
}
RegisterAndInitializePhysicsProxy();
SetDynamicState(Chaos::EObjectStateType::Dynamic);
//
//Set Any Collision Responses here BEFORE calling SetCollisionEnabled()
//
SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
SetNotifyBreaks(true);
OnActorEnableCollisionChanged();
// This is needed to assign our GeometryCollection events to work with our new PhysicsProxy
RegisterForEvents();
From what I saw if you are going to switch the RestCollection (Which in turn changes the DynamicCollection) you have to reset the PhysicsProxy.
It looks like UE 5.4 broke (or somewhat broke) how GeometryCollection Notifies work and unfortunately without having a manually compiled engine you cannot fix the issue. (yet)
SetNotifyBreaks(true) would immediately stop all break events from happening as soon as it got called. In 5.4 this is no longer the case. Calling SetNotifyBreaks(true) will allow on average 30 break events to get called until it is finally updated. The solution from what I have seen so far is to manually access the EventDispatcher and Unregister the event. However even if you parent GeometryCollectionComponent you do not have access to EventDispatcher since it is private.
I will give further updates as I look into finding a solution that would be doable with read-only engine code.
Any updates on this? I ran into the exact same problem, I was trying to have the Rest Collection changed whenever I pressed a specific button, and the engine keeps crashing…
I just managed to figure it out for blueprints. I have created new component in my actor BP (Geometry Collection Component), and set Rest Colection to one of my geometry collections by default (you need to set this to something otherwise it wont work). Then it will let you turn on/off physics and then you can turn them on/off when needed. In construction script i have Set Rest Collection from variable and it lets me change to whichever collection i want
I’m not sure if this is the perfect solution, but it is what I got working. To do this in blueprints, you need to set simulate physics to true after changing the rest collection. Then use “Set Per Level Collision Profile Names” to add the correct collisions back to Geometry Collection.