Skip to content

Commit

Permalink
Merge pull request #280 from Kyri123/Dev
Browse files Browse the repository at this point in the history
Add examples to Abstract Instances
  • Loading branch information
budak7273 authored Apr 5, 2024
2 parents 608130d + 435bfa5 commit 4ff7c0f
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions modules/ROOT/pages/Development/Satisfactory/AbstractInstance.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,66 @@ You may also find the following properties useful:
* Use Relative Transform to apply a transform this specific mesh relative to the overall building.
* If the building has no components set `mContainsComponents` on the buildable to false
* The "apply random offset" properties can be used to mitigate z-fighting issues when multiple copies of the building overlap.

[id="Examples"]
== Examples for Custom Implementations

`TArray< struct FInstanceHandle* > mInstanceHandles` All instance handlers (provided from `AFGBuildable` If you create a new actor, you should define something like that).

=== Resolve Hit on Abstract Instances

[NOTE]
====
Hits in Holograms are already resolved and don't need this implementation.
====

To resolve the hit, we have two options:

- Hit result `bool ResolveHit( const FHitResult& Result, FInstanceHandle& OutHandle )`
- Overlap Result `bool ResolveOverlap( const FOverlapResult& Result, FInstanceHandle& OutHandle )`

```cpp
ASMLActor::ResolveHitResult(const FHitResult& Hit) {
AAbstractInstanceManager* Manager = AAbstractInstanceManager::Get(GetWorld());
fgcheck(Manager);

FInstanceHandle OutHandle;
if(Manager->ResolveHit(Hit, OutHandle)) {
// We hit a abstract instance to we can get informations like the owner from that
OutHandle.GetOwner() // AActor* who owns the Instance
}
// We don't hit a abstract instance so we can continue with the Hit
}
```

=== Create Abstract Instances at Runtime

```cpp
static void SetInstanceFromDataStatic( AActor* OwnerActor, const FTransform& ActorTransform, const FInstanceData& InstanceData, FInstanceHandle* &OutHandle, bool bInitializeHidden = false );

ASMLActor::CreateInstanceFromMesh(UStaticMesh* Mesh) {
// Prepare the InstanceData with a given Mesh at the relative Transform 0.
FInstanceData InstanceData;
InstanceData.StaticMesh = Mesh;
InstanceData.Mobility = EComponentMobility::Static;
InstanceData.RelativeTransform = FTransform();
InstanceData.NumCustomDataFloats= 20;

FInstanceHandle* Handle;
AAbstractInstanceManager::SetInstanceFromDataStatic(this, GetActorTransform(), InstanceData, Handle);

// You should add this Handle to the array so we can destroy them if the actor is destroyed (for example, dismantled).
mInstanceHandles.Add(Handle);
}
```

=== Destory Abstract Instances at runtime

```cpp
static void RemoveInstances( UObject* WorldContext, TArray<FInstanceHandle*>& Handles, bool bEmptyHandleArray = true );

ASMLActor::ClearInstances(UStaticMesh* Mesh) {
// Will remove/destroy all instances and empty mInstanceHandles.
AAbstractInstanceManager::RemoveInstances( GetWorld( ), mInstanceHandles );
}
```

0 comments on commit 4ff7c0f

Please sign in to comment.