Skip to content

Commit

Permalink
Expose child actor obtainment function
Browse files Browse the repository at this point in the history
  • Loading branch information
nxrighthere committed Oct 19, 2020
1 parent 6066406 commit 92e01b2
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 2 deletions.
13 changes: 13 additions & 0 deletions API/ChildActorComponent-GetChildActor-T-().md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### [UnrealEngine.Framework](./UnrealEngine-Framework.md 'UnrealEngine.Framework').[ChildActorComponent](./ChildActorComponent.md 'UnrealEngine.Framework.ChildActorComponent')
## ChildActorComponent.GetChildActor<T>() Method
Gets the child actor
```csharp
public T GetChildActor<T>();
```
#### Type parameters
<a name='UnrealEngine-Framework-ChildActorComponent-GetChildActor-T-()-T'></a>
`T`

#### Returns
[T](#UnrealEngine-Framework-ChildActorComponent-GetChildActor-T-()-T 'UnrealEngine.Framework.ChildActorComponent.GetChildActor&lt;T&gt;().T')
An actor or `null` on failure
1 change: 1 addition & 0 deletions API/ChildActorComponent.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.O
### Constructors
- [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)')
### Methods
- [GetChildActor&lt;T&gt;()](./ChildActorComponent-GetChildActor-T-().md 'UnrealEngine.Framework.ChildActorComponent.GetChildActor&lt;T&gt;()')
- [SetChildActor&lt;T&gt;()](./ChildActorComponent-SetChildActor-T-().md 'UnrealEngine.Framework.ChildActorComponent.SetChildActor&lt;T&gt;()')
Binary file modified Content/Tests/Tests.umap
Binary file not shown.
6 changes: 4 additions & 2 deletions Source/Managed/Framework/Codegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace UnrealEngine.Framework {
// Automatically generated

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

internal static unsafe Dictionary<int, IntPtr> Load(IntPtr* events, IntPtr functions, Assembly pluginAssembly) {
int position = 0;
int position = 0;
IntPtr* buffer = (IntPtr*)functions;

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

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

Expand Down Expand Up @@ -1863,6 +1864,7 @@ unsafe partial class CameraComponent {
}

unsafe partial class ChildActorComponent {
internal static delegate* unmanaged[Cdecl]<IntPtr, ActorType, IntPtr> getChildActor;
internal static delegate* unmanaged[Cdecl]<IntPtr, ActorType, IntPtr> setChildActor;
}

Expand Down
17 changes: 17 additions & 0 deletions Source/Managed/Framework/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8563,6 +8563,23 @@ public ChildActorComponent(Actor actor, string name = null, bool setAsRoot = fal
Pointer = create(actor.Pointer, Type, name, setAsRoot, blueprint != null ? blueprint.Pointer : IntPtr.Zero);
}

/// <summary>
/// Gets the child actor
/// </summary>
/// <returns>An actor or <c>null</c> on failure</returns>
public T GetChildActor<T>() where T : Actor {
T actor = FormatterServices.GetUninitializedObject(typeof(T)) as T;
IntPtr pointer = getChildActor(Pointer, actor.Type);

if (pointer != IntPtr.Zero) {
actor.Pointer = pointer;

return actor;
}

return null;
}

/// <summary>
/// Sets the child actor
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions Source/Managed/Tests/ExternalConsistency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ private void ChildActorsTest() {
ChildActorComponent childActorComponent = new(actor, setAsRoot: true);
TriggerBox childActor = childActorComponent.SetChildActor<TriggerBox>();

if (childActor == null) {
Debug.Log(LogLevel.Error, "Child actor creation check failed!");

return;
}

childActor = childActorComponent.GetChildActor<TriggerBox>();

if (childActor == null) {
Debug.Log(LogLevel.Error, "Child actor obtainment check failed!");

Expand Down
1 change: 1 addition & 0 deletions Source/Native/Source/UnrealCLR/Private/UnrealCLR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ void UnrealCLR::Module::StartupModule() {
int32 head = 0;
Shared::Functions[position++] = Shared::ChildActorComponentFunctions;

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

checksum += head;
Expand Down
8 changes: 8 additions & 0 deletions Source/Native/Source/UnrealCLR/Private/UnrealCLRFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2599,6 +2599,14 @@ namespace UnrealCLRFramework {
}

namespace ChildActorComponent {
AActor* GetChildActor(UChildActorComponent* ChildActorComponent, ActorType Type) {
AActor* actor = nullptr;

UNREALCLR_GET_ACTOR_TYPE(Type, Cast<, >(ChildActorComponent->GetChildActor()), actor);

return actor;
}

AActor* SetChildActor(UChildActorComponent* ChildActorComponent, ActorType Type) {
TSubclassOf<AActor> type;

Expand Down
1 change: 1 addition & 0 deletions Source/Native/Source/UnrealCLR/Public/UnrealCLRFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ namespace UnrealCLRFramework {
}

namespace ChildActorComponent {
static AActor* GetChildActor(UChildActorComponent* ChildActorComponent, ActorType Type);
static AActor* SetChildActor(UChildActorComponent* ChildActorComponent, ActorType Type);
}

Expand Down

0 comments on commit 92e01b2

Please sign in to comment.