Announcement

Collapse
No announcement yet.

Static Utils Class

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

    Static Utils Class

    I'm trying to make a static utils class which functions can be used from anywhere, however when I try to access the functions from other classes, the Utils class is not found.

    As you guessed, I'm new to C++.

    What am I doing wrong?

    https://www.dropbox.com/s/7ak6z8ms25r3jxc/static.png

    #2
    Since you haven't showed us an attempted usage or the error I can only guess. But my first inclination is that you didn't #include "Utils.h" in the source file trying to use the class.

    Comment


      #3
      I did actually include it, here's my attempt to use Utils:

      https://www.dropbox.com/s/jb0tee4rc2teq74/static2.png

      While we're at it, is there also a possibility to use it without including it?

      It seems like Unreal already has a class named "Utils", and that the one I created was deleted somehow. I'll see if that's the problem.
      Last edited by RoyiBernthal; 04-12-2014, 03:11 PM.

      Comment


        #4
        My Static Function Libraries Wiki Tutorial

        https://wiki.unrealengine.com/Static..._Compile_Times

        Enjoy!

        Rama
        UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

        ♥ Rama

        Comment


          #5
          Thanks Rama looks great!

          When I'm creating new classes they're always moved to Intermediate\ProjectFiles instead of Source\Test. Any idea why and what's the difference?

          Also is the ".generated.h" automatically created for classes I add via Unreal Editor? Should I only create new classes via Unreal Editor?
          Last edited by RoyiBernthal; 04-12-2014, 03:40 PM.

          Comment


            #6
            I did some research and it seems like I must always add new classes via File -> Add Code To Project in Unreal Editor, and in the most simple case base it on UObject. Please correct me if I'm wrong.

            Is there a way to make the static class automatically accessible to other classes in the project without having to include its header every time?

            Comment


              #7
              You totally are not forced to use "Add Code To Project" only. Yes, in most of the cases your classes will be derived from UObject.

              To make your class accessible anywhere with out the need to manually include it everywhere you could include it in your precompiled header, which should be "YourProjectName.h", include it right after Engine.h.
              Take a note, precompiled header is included in every .cpp file, so if you want to use your class in header files also(like inline functions) you have to include header for your class in that header as well.
              Alone: The Untold - a story driven horror game

              Comment


                #8
                When I don't use "Add Code To Project" I always have trouble connecting it with the rest of the code. Could you please see what I wrote in one of my above replies about the folder my classes are moved to?

                Making it accessible everywhere - yup good idea.

                Comment


                  #9
                  I add code manually via "Add - New Item" and add .h and .cpp files separately, you should be able to choose location where to create these files.
                  Click image for larger version

Name:	p869fvN.png
Views:	1
Size:	43.7 KB
ID:	1050041
                  And they should always be located in YourProject\Source\YourProjectName.
                  Not exactly like this, they should be located in the corresponding game module directory, but ignore that for a while, you have only one module currently, and its directory is "YourProjectName". Check documentation on Unreal Build Tool for a better understanding of this(don't forget about game samples as well).
                  Alone: The Untold - a story driven horror game

                  Comment


                    #10
                    Thanks I guess I missed that. I'm guessing the other classes in the same project couldn't find the new classes because of their different location?

                    Comment


                      #11
                      Yes. Search paths could be added in YourProject.build.cs using the following line:
                      Code:
                      PrivateIncludePaths.AddRange(new string[] { "SomePath", "AnotherPath" } );
                      By default it looks for headers in module directory, if you want to create sub-directory for your files you'll have to add them in *.builld.cs
                      Alone: The Untold - a story driven horror game

                      Comment


                        #12
                        Gotcha, thanks.

                        Comment

                        Working...
                        X