x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Getting location from a UActorComponent

So as the question says. I know it not really possible but I have an array of UActorComponents from using getCompoentByClass and I need to be able to get the location and set velocities of the components when I've done it in blueprint it's fine because the array returned is of type UStaticMeshComponent not UActorComponent. This is what I have currently and the issue it within the for loop when I'm trying to receive the location for the component.

 TArray<UActorComponent*> StaticMeshComps;
  StaticMeshComps = actorHit->GetComponentsByClass(UStaticMeshComponent::StaticClass());
  
  for (int y = 0; y < StaticMeshComps.Num(); y++)
  {
      UE_LOG(LogTemp, Warning, TEXT("Static Mesh: %s"), *StaticMeshComps[y]->GetName());
  
      FVector MeshLocation = StaticMeshComps[y]->GetComponentLocation();
  }

is there any way to change the code i have to make it work or anything else?

Product Version: UE 4.12
Tags:
more ▼

asked Feb 16 '17 at 01:15 PM in C++ Programming

avatar image

Djekko
14 8 10 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I've managed to figure this one out but ill post the solution anyway as it took me a while to get what I needed.

So once I had my array of UActorComponents I was trying to cast the whole Array over to UStaticMeshComponet but I was having difficulties. In the end, I passed the array into the for loop like before and then once dealing with individual components I was able to cast the component type over.

This is what I ended up with and it works perfectly for me.

 TArray<UActorComponent*> StaticMeshComps;
 StaticMeshComps = actorHit->GetComponentsByClass(UStaticMeshComponent::StaticClass());
 
 for (int y = 0; y < StaticMeshComps.Num(); y++)
 {
     UStaticMeshComponent* MeshComp = Cast<UStaticMeshComponent>(StaticMeshComps[y]);
 
     FVector MeshLocation = MeshComp->GetComponentLocation();
 
        //Rest of Code
 }

more ▼

answered Feb 16 '17 at 04:37 PM

avatar image

Djekko
14 8 10 10

avatar image basania.d Jun 26 '18 at 11:40 AM

Thank you so much! You helped me a lot.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question