Announcement

Collapse
No announcement yet.

"UGameplayStatics::GetAllActorsOfClass" is inaccessible

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

    "UGameplayStatics::GetAllActorsOfClass" is inaccessible

    Hey guys! I've been getting an error in visual studio which is keeping my project from compiling and i'm not entirely sure why.

    #2
    You have to include its module in your build.cs file and then include its header in your code.
    | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

    Comment


      #3
      Is it actually preventing your project from compiling or is it just in your IDE's error list?

      I don't know about 4.21 as I haven't migrated from 4.20 yet, but if you're in 4.20 there's some known bugs about Visual Studio intellisense. I myself see this inaccessible message quite often for no reason whatsoever. You can always go see the header of UGameplayStatics and see for yourself if the function is actually public or not. Spoiler, it will be

      Comment


        #4
        I don't why they use error list panel... Epic has guides explaining why it doesn't work with Unreal code..
        | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

        Comment


          #5
          Originally posted by Altrue View Post
          Is it actually preventing your project from compiling or is it just in your IDE's error list?

          I don't know about 4.21 as I haven't migrated from 4.20 yet, but if you're in 4.20 there's some known bugs about Visual Studio intellisense. I myself see this inaccessible message quite often for no reason whatsoever. You can always go see the header of UGameplayStatics and see for yourself if the function is actually public or not. Spoiler, it will be
          It's actually preventing it from compiling which is odd because I thought it was a false positive at first. The code is part of a course i'm taking for which that code is being prepped for blueprint

          Comment


            #6
            Originally posted by BrUnO XaVIeR View Post
            You have to include its module in your build.cs file and then include its header in your code.
            Thanks for the reply mate! Although I still don't quite understand. Would it be helpful if I posted my project files?

            Comment


              #7
              Inaccessible means it's not public. That function only exists to expose the functionality for blueprints. In C++ you use TActorIterator, which is what that function uses:

              Code:
              // With hard coded class
              for (TActorIterator<AMyActorClass*> ActorItr(GetWorld()); ActorItr; ++ActorItr)
              {
                // do stuff with your actor here using ActorItr
              }
              
              // With a class parameter called
              TSubClassOf<AActor> ClassParam = AMyActorClass::StaticClass();
              for (TActorIterator<AActor*> ActorItr(GetWorld(), ClassParam); ActorItr; ++ActorItr)
              {
                // do stuff with your actor here using ActorItr
              }

              Comment


                #8
                The function is static, it is accessible from anywhere if the module and header file are properly included.
                | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                Comment


                  #9
                  Yeah that's weird, there's no reason not to use GetAllActorsOfClass in c++. Maybe an issue with your included headers? Make sure that at some point you are including the core includes (engine.h etc... I think ?), usually through including your project.h which itself includes the required stuff.

                  You could try to directly include the header for UGameplayStatics and see if that works, though only as a debugging tool, it's too dirty as an actual solution.

                  This does not explain why your IDE would show an inaccessible error, but that may be a false positive hiding something else.
                  Last edited by Altrue; 11-19-2018, 06:23 AM.

                  Comment


                    #10
                    Is this method r better than actor iterator?

                    Comment


                      #11
                      It is an actor iterator, so nope!

                      Comment


                        #12
                        Originally posted by Altrue View Post
                        This does not explain why your IDE would show an inaccessible error, but that may be a false positive hiding something else.
                        The IDE shows an inaccessible error because of the difference between GENERATED_BODY() and GENERATED_UCLASS_BODY(). The latter emits a public specifier at the end and the first one does not. Older source uses the latter macro like in UGameplayStatics

                        Code:
                        // .. headers
                        
                        UCLASS()
                        class ENGINE_API UGameplayStatics : public UBlueprintFunctionLibrary
                        {
                            GENERATED_UCLASS_BODY()
                        
                        //===============
                        // some static functions here
                        //================
                        
                            UFUNCTION(BlueprintCallable, Category="Utilities",  meta=(WorldContext="WorldContextObject", DeterminesOutputType="ActorClass", DynamicOutputParam="OutActors"))
                            static void GetAllActorsOfClass(const UObject* WorldContextObject, TSubclassOf<AActor> ActorClass, TArray<AActor*>& OutActors);
                        
                        //=========
                        // rest of the source here
                        //============
                        
                        };
                        Notice there is no "public:" identifier between the start of the class, the macro and the getallactors function. In c++ if you don't add an access specifier everything is assumed private. This is an error because the public specifier is supposed to be emiited from the macro which the IDE seems unable to comprehend. Contrast this with new code that uses the GENERATED_BODY() macro where the specifier is not assumed and will be explicitly provided in the source. So everything works there.

                        That still leaves false positive all over the codebase and apparently Epic has decided this is not important it has still not been fixed in 4.21
                        UE4 Tutorials for 3rd person Blueprint project from scratch: Youtube Channel
                        Use Blender 2.8 to make UE4 compatible animations: Blog

                        Comment


                          #13
                          Hey all thank you so much for your help!

                          Comment

                          Working...
                          X