Announcement

Collapse
No announcement yet.

Creating a static member variable in UE pawn class

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

    Creating a static member variable in UE pawn class

    Hi, I am a very new learner, so I am sorry in advance. I am currently following along a tutorial and am confused


    Click image for larger version

Name:	Capture3.PNG
Views:	30
Size:	423.1 KB
ID:	1685114

    Here, the pawn class is called Collider. Is it okay for you to declare and initialize a static variable of type FObjectFinder inside a constructor? Would that not defeat the purpose of it being static (not related to any instance of Collider)? Also, out of curiousity, I was trying to declare a static class member of type FObjectFinder in my Collider.h file, before initializing it in Collider.cpp file (just like how you declare and initialize static class members in normal C++)


    In my header file:
    Click image for larger version

Name:	Capture.PNG
Views:	30
Size:	38.0 KB
ID:	1685115

    In my cpp file
    Click image for larger version

Name:	Capture2.PNG
Views:	30
Size:	5.3 KB
ID:	1685116

    However, it said that the class member is not found. It seems that the error is solved if I include #include "UObject/ConstructorHelpers.h" in the header file. However, this crashes my UE and it refuses to open. My question is simply then: how would I declare and initialize a static class member of type FObjectFinder? What is the code and includes for both .h and .cpp files? Thanks in advance!
    Attached Files

    #2
    MeshComponent varies by instance. (e.g. There is a different component instance on each pawn.) But the skeletal mesh asset that each MeshComponent uses is the _same_ asset. It does not vary by instance. FObjectFinder is also a helper object that does not vary by instance. It is a global helper to find the asset. So everytime the helper finds the same asset.

    Hope that clarifies.
    https://www.casualdistractiongames.com

    Comment


      #3
      Yes, I understand that part. But that still does not explain why I am not able to create FObjectFinder as a static class member in my .h file (instead of declaring and instantiating as a local static variable in my constructor in the .cpp file).

      Comment

      Working...
      X