Header file is seen only in one file

Hello everyone!

I’ve got a problem: I’m writing a code for spawning units. So I have four files in total: “Barracks.h”, “Barracks.cpp” — is an actor class, and “BarracksUnit.h”, “BarracksUnit.cpp” — is a character class. There is UParticleSystemComponent called “SpawnPoint”, that participates in each implementation file.

So the problem is that “SpawnPoint” is seen only in “Barracks.cpp” because I declare it in “Barracks.h” file. Despite having included “Barracks.h” in “BarracksUnit.cpp” in “BarracksUnit.cpp” it doesn’t recognize “Spawn Point” and keep warning that identifier is not identified.

What I have tried:

  1. Switch files with declaration. So that I declared “Spawn Point” in “BarracksUnit.h” and included this header file to “Barracks.cpp”. It started recognizing “Spawn Point” in “BarracksUnit.cpp” but the same problem appeared in “Barracks.cpp”. So switching keeps the same issue
  2. Declare “Spawn point” in both “Barracks.h” and “BarracksUnit.h” files. It makes Unreal crush. So this didn’t work for me either.

So what can be done?
Screenshot 2023-12-31 133508


Just including Barracks.h does not magically make it’s SpawnPoint accessible. You would need a reference to a Barracks class inside of your ABarracksUnit to be able to access it’s spawn point via the reference.

Also setup attachment is purely for the CDO do not put it in begin play.

In BarracksUnit you get a crash because you are not using CreateDefaultSubObject for the spawnpoint, so accessing it in an unitialized state causes you to access a null pointer which is bad new → leading straight to a crash.

There should be no problem defining the same uproperty in both headers. The crash is caused by the nullptr.

1 Like

Thank very much! I followed your advise and the error disappeared.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.