Skip to content

Commit 92e01b2

Browse files
committed
Expose child actor obtainment function
1 parent 6066406 commit 92e01b2

9 files changed

Lines changed: 53 additions & 2 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### [UnrealEngine.Framework](./UnrealEngine-Framework.md 'UnrealEngine.Framework').[ChildActorComponent](./ChildActorComponent.md 'UnrealEngine.Framework.ChildActorComponent')
2+
## ChildActorComponent.GetChildActor<T>() Method
3+
Gets the child actor
4+
```csharp
5+
public T GetChildActor<T>();
6+
```
7+
#### Type parameters
8+
<a name='UnrealEngine-Framework-ChildActorComponent-GetChildActor-T-()-T'></a>
9+
`T`
10+
11+
#### Returns
12+
[T](#UnrealEngine-Framework-ChildActorComponent-GetChildActor-T-()-T 'UnrealEngine.Framework.ChildActorComponent.GetChildActor&lt;T&gt;().T')
13+
An actor or `null` on failure

API/ChildActorComponent.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.O
88
### Constructors
99
- [ChildActorComponent(UnrealEngine.Framework.Actor, string, bool, UnrealEngine.Framework.Blueprint)](./ChildActorComponent-ChildActorComponent(Actor_string_bool_Blueprint).md 'UnrealEngine.Framework.ChildActorComponent.ChildActorComponent(UnrealEngine.Framework.Actor, string, bool, UnrealEngine.Framework.Blueprint)')
1010
### Methods
11+
- [GetChildActor&lt;T&gt;()](./ChildActorComponent-GetChildActor-T-().md 'UnrealEngine.Framework.ChildActorComponent.GetChildActor&lt;T&gt;()')
1112
- [SetChildActor&lt;T&gt;()](./ChildActorComponent-SetChildActor-T-().md 'UnrealEngine.Framework.ChildActorComponent.SetChildActor&lt;T&gt;()')

Content/Tests/Tests.umap

0 Bytes
Binary file not shown.

Source/Managed/Framework/Codegen.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace UnrealEngine.Framework {
2626
// Automatically generated
2727

2828
internal static class Shared {
29-
internal const int checksum = 0x2C3;
29+
internal const int checksum = 0x2C4;
3030
internal static Dictionary<int, IntPtr> userFunctions = new();
3131
private const string dynamicTypesAssemblyName = "UnrealEngine.DynamicTypes";
3232
private static readonly ModuleBuilder moduleBuilder = AssemblyBuilder.DefineDynamicAssembly(new(dynamicTypesAssemblyName), AssemblyBuilderAccess.RunAndCollect).DefineDynamicModule(dynamicTypesAssemblyName);
@@ -39,7 +39,7 @@ internal static class Shared {
3939
private const TypeAttributes delegateTypeAttributes = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.AnsiClass | TypeAttributes.AutoClass;
4040

4141
internal static unsafe Dictionary<int, IntPtr> Load(IntPtr* events, IntPtr functions, Assembly pluginAssembly) {
42-
int position = 0;
42+
int position = 0;
4343
IntPtr* buffer = (IntPtr*)functions;
4444

4545
unchecked {
@@ -635,6 +635,7 @@ internal static unsafe Dictionary<int, IntPtr> Load(IntPtr* events, IntPtr funct
635635
int head = 0;
636636
IntPtr* childActorComponentFunctions = (IntPtr*)buffer[position++];
637637

638+
ChildActorComponent.getChildActor = (delegate* unmanaged[Cdecl]<IntPtr, ActorType, IntPtr>)childActorComponentFunctions[head++];
638639
ChildActorComponent.setChildActor = (delegate* unmanaged[Cdecl]<IntPtr, ActorType, IntPtr>)childActorComponentFunctions[head++];
639640
}
640641

@@ -1863,6 +1864,7 @@ unsafe partial class CameraComponent {
18631864
}
18641865

18651866
unsafe partial class ChildActorComponent {
1867+
internal static delegate* unmanaged[Cdecl]<IntPtr, ActorType, IntPtr> getChildActor;
18661868
internal static delegate* unmanaged[Cdecl]<IntPtr, ActorType, IntPtr> setChildActor;
18671869
}
18681870

Source/Managed/Framework/Framework.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8563,6 +8563,23 @@ public ChildActorComponent(Actor actor, string name = null, bool setAsRoot = fal
85638563
Pointer = create(actor.Pointer, Type, name, setAsRoot, blueprint != null ? blueprint.Pointer : IntPtr.Zero);
85648564
}
85658565

8566+
/// <summary>
8567+
/// Gets the child actor
8568+
/// </summary>
8569+
/// <returns>An actor or <c>null</c> on failure</returns>
8570+
public T GetChildActor<T>() where T : Actor {
8571+
T actor = FormatterServices.GetUninitializedObject(typeof(T)) as T;
8572+
IntPtr pointer = getChildActor(Pointer, actor.Type);
8573+
8574+
if (pointer != IntPtr.Zero) {
8575+
actor.Pointer = pointer;
8576+
8577+
return actor;
8578+
}
8579+
8580+
return null;
8581+
}
8582+
85668583
/// <summary>
85678584
/// Sets the child actor
85688585
/// </summary>

Source/Managed/Tests/ExternalConsistency.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,14 @@ private void ChildActorsTest() {
286286
ChildActorComponent childActorComponent = new(actor, setAsRoot: true);
287287
TriggerBox childActor = childActorComponent.SetChildActor<TriggerBox>();
288288

289+
if (childActor == null) {
290+
Debug.Log(LogLevel.Error, "Child actor creation check failed!");
291+
292+
return;
293+
}
294+
295+
childActor = childActorComponent.GetChildActor<TriggerBox>();
296+
289297
if (childActor == null) {
290298
Debug.Log(LogLevel.Error, "Child actor obtainment check failed!");
291299

Source/Native/Source/UnrealCLR/Private/UnrealCLR.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ void UnrealCLR::Module::StartupModule() {
804804
int32 head = 0;
805805
Shared::Functions[position++] = Shared::ChildActorComponentFunctions;
806806

807+
Shared::ChildActorComponentFunctions[head++] = (void*)&UnrealCLRFramework::ChildActorComponent::GetChildActor;
807808
Shared::ChildActorComponentFunctions[head++] = (void*)&UnrealCLRFramework::ChildActorComponent::SetChildActor;
808809

809810
checksum += head;

Source/Native/Source/UnrealCLR/Private/UnrealCLRFramework.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,6 +2599,14 @@ namespace UnrealCLRFramework {
25992599
}
26002600

26012601
namespace ChildActorComponent {
2602+
AActor* GetChildActor(UChildActorComponent* ChildActorComponent, ActorType Type) {
2603+
AActor* actor = nullptr;
2604+
2605+
UNREALCLR_GET_ACTOR_TYPE(Type, Cast<, >(ChildActorComponent->GetChildActor()), actor);
2606+
2607+
return actor;
2608+
}
2609+
26022610
AActor* SetChildActor(UChildActorComponent* ChildActorComponent, ActorType Type) {
26032611
TSubclassOf<AActor> type;
26042612

Source/Native/Source/UnrealCLR/Public/UnrealCLRFramework.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ namespace UnrealCLRFramework {
838838
}
839839

840840
namespace ChildActorComponent {
841+
static AActor* GetChildActor(UChildActorComponent* ChildActorComponent, ActorType Type);
841842
static AActor* SetChildActor(UChildActorComponent* ChildActorComponent, ActorType Type);
842843
}
843844

0 commit comments

Comments
 (0)