Announcement

Collapse
No announcement yet.

Trouble adding component at 0,0,0 relative to parent

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

    Trouble adding component at 0,0,0 relative to parent

    I have this code here:
    Code:
    int32 hismCount = TileMeshInstances.Num();
    FString hismName = FString::Printf(TEXT("TileMeshInstance_%d"), hismCount);
    UHierarchicalInstancedStaticMeshComponent* hism = NewObject<UHierarchicalInstancedStaticMeshComponent>(this, UHierarchicalInstancedStaticMeshComponent::StaticClass(), *hismName);
    hism->RegisterComponent();
    hism->AttachTo(this->GetRootComponent());
    hism->SetRelativeLocation(FVector(0, 0, 0));
    //hism->SetWorldLocation(this->GetActorLocation());
    hism->SetStaticMesh(tileMesh);
    UE_LOG(LogTemp, Display, TEXT("Using transform for instance: %s"), *tile->Transform.ToString());
    hism->AddInstance(tile->Transform);
    TileMeshInstances.Add(tileMesh, hism);
    I want the created Hierarchical Instanced Static Mesh component (HISM) to be at 0,0,0 relative to the parent class, but not matter what I do it always ends up at 0,0,0 in World space.

    #2
    Hmm I wonder if the problem is actually with the instances I am adding to the HISM. Is HISM->AddInstance in local or world space? It doesn't say and I am assuming it is in local space, but maybe not.

    EDIT: Nevermind I just looked it up in the docs and it is indeed local space. So my problem still remains.

    Comment


      #3
      Anyone have any ideas? This is driving me crazy and it should be super simple. I'm not sure what I am doing wrong.

      Comment


        #4
        Have you tried:

        Code:
        hism->AttachTo(this->GetRootComponent(), NAME_None, EAttachLocation::SnapToTarget);
        Attach to defaults to KeepRelativeOffset. The above is what I use to set the position of an object to match another exactly. (You could also use SnapToTargetIncludingScale if you want to match the scale too)
        NVIDIA GameWorks merged branch (v4.9.2) (v4.12.5) (v4.13 p2)
        Feel free to Donate if you wish to support me

        Comment


          #5
          Originally posted by GalaxyMan2015 View Post
          Have you tried:

          Code:
          hism->AttachTo(this->GetRootComponent(), NAME_None, EAttachLocation::SnapToTarget);
          Attach to defaults to KeepRelativeOffset. The above is what I use to set the position of an object to match another exactly. (You could also use SnapToTargetIncludingScale if you want to match the scale too)
          Well that sounded most logical, however no luck It still isn't showing up in the right place.

          EDIT: Ok this is odd. Apparently the actor doesn't actually know where it is when I am setting up. I am doing this in a function called during OnConstruction(). The strange thing is that the call to OnConstruction passes in a transform and that transform has the actor's correct position. But apparently the actor itself doesn't know that yet, because if you ask the actor where it is, it thinks it is at 0,0,0.
          Last edited by John Vanderbeck; 09-11-2015, 10:32 AM.

          Comment

          Working...
          X