Announcement

Collapse
No announcement yet.

Using ForEachSelectedActor blutility function?!

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

    Using ForEachSelectedActor blutility function?!

    Does anyone know how to use the "ForEachSelectedActor" and "ForEachSelectedAsset" functions available in Blutilities? They don't have any output pins, they just call "OnEachSelectedActor" and "OnEachSelectedAsset" functions. Can someone show an example or explain how they work?

    Thanks!
    Stephane Roncada
    Lead Technical Artist | Environment Artist
    Rainbow Studios

    #2
    bump...
    Stephane Roncada
    Lead Technical Artist | Environment Artist
    Rainbow Studios

    Comment


      #3
      It's pretty straight forward. If you call "ForEachSelectedActor", it will gather all Actors that you selected in your Editor Level (at least that's the only "Selected Actors" I know),
      and then iterates over them and calls "OnEachSelectedActor" for each of the Actors you've selected. Sounds a bit weird, but it's simply a for each loop that gives you all Actors, one by one,
      that you selected in the Level. Same probably happens for the Asset version.

      Here is the C++ code of that function:

      Code:
      void UGlobalEditorUtilityBase::ForEachSelectedActor()
      {
      	TArray<AActor*> SelectionSetCache;
      	for (FSelectionIterator It(GEditor->GetSelectedActorIterator()); It; ++It)
      	{
      		if (AActor* Actor = Cast<AActor>(*It))
      		{
      			SelectionSetCache.Add(Actor);
      		}
      	}
      
      	int32 Index = 0;
      	for (auto ActorIt = SelectionSetCache.CreateIterator(); ActorIt; ++ActorIt)
      	{
      		AActor* Actor = *ActorIt;
      		OnEachSelectedActor.Broadcast(Actor, Index);
      		++Index;
      	}
      }
      Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

      My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
      (Including 100+ Pages Multiplayer Network Compendium to get you started.)

      Comment


        #4
        Hi eXi and thanks for the info.

        So using that function, how do I access the selected actor? I see it is broadcasting the Actor at Index, but how to I get a reference to the actual Actor?

        Thanks!
        Stephane Roncada
        Lead Technical Artist | Environment Artist
        Rainbow Studios

        Comment


          #5
          You probably must declare custom delegate to match this criteria for it to work:

          Code:
          DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams( FForEachActorIteratorSignature, class AActor*, Actor, int32, Index );
          DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams( FForEachAssetIteratorSignature, class UObject*, Asset, int32, Index );
          Then when you bind them blutility should execute code you specified on them.. I did not tested this yet but plan to use this so I'm drilling through source to look at what it have to offer. UE4 would benefit great deal from more usage examples/documentation

          Try to look here for some ideas what can be done:GlobalEditorUtilityBase.h

          Comment


            #6
            Thanks Vertex Soup, I'll look into that!

            Originally posted by Vertex Soup View Post
            You probably must declare custom delegate to match this criteria for it to work:

            Code:
            DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams( FForEachActorIteratorSignature, class AActor*, Actor, int32, Index );
            DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams( FForEachAssetIteratorSignature, class UObject*, Asset, int32, Index );
            Then when you bind them blutility should execute code you specified on them.. I did not tested this yet but plan to use this so I'm drilling through source to look at what it have to offer. UE4 would benefit great deal from more usage examples/documentation

            Try to look here for some ideas what can be done:GlobalEditorUtilityBase.h
            Stephane Roncada
            Lead Technical Artist | Environment Artist
            Rainbow Studios

            Comment


              #7
              I found the ForEachSelectedActor in Blueprint. Even after reading above, I can not figure out how it works. Can someone show an example of it being used inside Blueprint ?

              Comment


                #8
                Originally posted by Tuxmask75 View Post
                I found the ForEachSelectedActor in Blueprint. Even after reading above, I can not figure out how it works. Can someone show an example of it being used inside Blueprint ?
                I don't know if you still need this, but here's an example.
                https://imgur.com/LoRZcBm

                Comment


                  #9
                  Originally posted by Fabsterpal View Post

                  I don't know if you still need this, but here's an example.
                  https://imgur.com/LoRZcBm
                  Thanks, that looks pretty straight-forward!
                  Stephane Roncada
                  Lead Technical Artist | Environment Artist
                  Rainbow Studios

                  Comment

                  Working...
                  X