iterate actors?

Glad you got it working.
Also it may be good to check if its a valid object or not, before you use it.


/**
	 * Checks to see if the object appears to be valid
	 * @return true if this appears to be a valid object
	 */
ActorItr->IsValidLowLevel();

ok thanks for the tip :slight_smile:
guess it was working all along, just it wasnt Ticking
is it working, now i can carry on making the game hehe

big thanks to everyone

Sweet implementation! Interested to know how your game will use this.

im recreating the gravity monk, can be seen at around 2 min 30 , and at the end https://www.youtube.com/watch?v=bPsz67N8fX8
but depending on a few things it might be used for planets or something.
im making the next generation of teg’s playground (this is prob the best vid https://www.youtube.com/watch?v=TjFoyUZJMoQ),
the next one might be set in space i dont know.

Rad. Reminds me of Saints Row 3 minus the juvenile nature.

's my Solution



TArray<UPrimitiveComponent*> OverlappedComponents; // UPrimitiveComponent works only on all objects which support PHYSICS
    OuterSphereComp->GetOverlappingComponents(OverlappedComponents);

    UPrimitiveComponent* PrimComp;
    if (OverlappedComponents.Num() > 0) {
        for (int i = 0; i < OverlappedComponents.Num(); i++) {
            PrimComp = OverlappedComponents*;
            // some actions you want to do
        }
    }

or if you wish to get all actors of class(specified), you can use it. In my example I iterated over PlayerControllers


// .cpp

TArray<AActor*> ReturnedActors;
UGameplayStatics::GetAllActorsOfClass(this, SpectatingViewPointClass, ReturnedActors);
// Change view target if any actor found
    if (ReturnedActors.Num() > 0){
        AActor* NewViewTarget = ReturnedActors[0];
        for (FConstPlayerControllerIterator contrIt = GetWorld()->GetPlayerControllerIterator(); contrIt; contrIt++) {
            // you actions
        }
    }

// .h
TSubclassOf<AActor> SpectatingViewPointClass;

Why bump such an old thread? Also why use GetActorsOfClass?



for (AActor* ViewPoint : TActorRange<AActor>(GetWorld(), SpectatingViewPointClass))
{
   NewViewTarget = ViewPoint;
}

I am not that experienced with ue4, so I posted what I have, to help others!
I used this one to iterate all the characters, get PC(PlayerController), and then disable input…

Could You please explain your code?

Code:
for (AActor* ViewPoint : TActorRange(GetWorld(), SpectatingViewPointClass)) { NewViewTarget = ViewPoint; } conventional for loop looks like this:


for(int i = 0; i < someVar.length; i++){...}

but your is different you have


AActor* ViewPoint : TActorRange<AActor>(GetWorld()

what does the colon mean in this expression? // documentaion is but helpful for this one. // DOC`s description: ***Template actor range for ranged-for support. ***What a Template is clear for me. But the other text does not make sense. ranged-for support. what? Hope to see some explanation. Thank you and have a good day!:wink:

Does a TObjectIterator find the Objects in the world automatically ?
And is a TObjectIterator really faster than a GetAllActorsOfClass ?

No. TObjectIterator will loop everything of class including assets and instances outside game world (in editor).
There are situations where it’s needed, but not for this.

The “for (x : y)” loop syntax is modern syntax where some popular things from Java have been incorporated into the C++ language.
Many snob veterans dislike these “javascript features in C”.

That hit hard on a personal level…

Keep it up. We got Thomas Edison’s quote on our side - “I have not failed. I’ve just found 10,000 ways that won’t work.”