Announcement

Collapse
No announcement yet.

Difference between GetDefaultSubobjects and GetDefaultSubobjectByName?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Difference between GetDefaultSubobjects and GetDefaultSubobjectByName?

    Is there any difference on what the object type returned, when using GetDefaultSubobjects and GetDefaultSubobjectByName?
    Is one of them returning reference and the other not?

    This works:
    Code:
    TArray<UObject*> ObjectArray;
    GetDefaultSubobjects(ObjectArray);
    for (UObject* Mesh_1P : ObjectArray)
    {
        if (Mesh_1P->GetName() == "FirstPersonMesh")
        {
            Cast<USkeletalMeshComponent>(Mesh_1P)->SetRelativeLocation(FVector(15.0f, 0.0f, 0.0f));
            Cast<USkeletalMeshComponent>(Mesh_1P)->SetRelativeRotation(FRotator(0.0f, 180.0f, 0.0f));
            Cast<USkeletalMeshComponent>(Mesh_1P)->bOnlyOwnerSee = true;
            Cast<USkeletalMeshComponent>(Mesh_1P)->bOwnerNoSee = false;
            Cast<USkeletalMeshComponent>(Mesh_1P)->bCastDynamicShadow = false;
            Cast<USkeletalMeshComponent>(Mesh_1P)->CastShadow = false;
            Cast<USkeletalMeshComponent>(Mesh_1P)->SetSkeletalMesh(CustomMesh_1P);
        }
    }

    This doesn't:
    Code:
    UObject* Mesh_1P = Cast<USkeletalMeshComponent>(GetClass()->GetDefaultSubobjectByName(TEXT("FirstPersonMesh")));
    if (Mesh_1P->GetName() == "FirstPersonMesh")
    {
        Cast<USkeletalMeshComponent>(Mesh_1P)->SetRelativeLocation(FVector(15.0f, 0.0f, 0.0f));
        Cast<USkeletalMeshComponent>(Mesh_1P)->SetRelativeRotation(FRotator(0.0f, 180.0f, 0.0f));
        Cast<USkeletalMeshComponent>(Mesh_1P)->bOnlyOwnerSee = true;
        Cast<USkeletalMeshComponent>(Mesh_1P)->bOwnerNoSee = false;
        Cast<USkeletalMeshComponent>(Mesh_1P)->bCastDynamicShadow = false;
        Cast<USkeletalMeshComponent>(Mesh_1P)->CastShadow = false;
        Cast<USkeletalMeshComponent>(Mesh_1P)->SetSkeletalMesh(CustomMesh_1P);
    }
    But while using the second code segment, I don't see the USkeletalMeshComponent while in game.
    From what I can see while debugging Mesh_1P is the same class regardless of the two I use(UObject). So I can't figure out why there is a difference?


    Code:
    UObject * GetDefaultSubobjectByName
    (
        FName ToFind
    )
    Code:
    void GetDefaultSubobjects
    (
        TArray< UObject * > & OutDefaultSubobjects
    )

    #2
    Might not be relevant but here is some more info:

    I'm using this in the Pawn class.
    In both cases I get inside the If statement.. It just seem that setting the properties and calling SetSkeletalMesh does not do anything.

    Comment

    Working...
    X