I have a spawner object blueprint instantiated in my default map, as well, whose job is to intermittently spawn fence objects (but that’s a matter for later.) In order to synchronize states between the player and the spawner (such as the player clicking to start the map,) I have assigned a UPROPERTY of the BP_EaglePawn meant to house the spawner actor. However, when I select it as shown, it does not populate in the dropdown menu (the selection remains None.)
The EaglePawn.h file designates this as such:
class SCREECHTEST_API AEaglePawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AEaglePawn();
//... other code here, but is not relevant to question
//Have a reference to a spawner object so that states can be synchronized
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawner")
AObstacleSpawner* Spawner;
I may not understand your application, but my guess is this.
EaglePawn will need to use an Actor Iterator to find the other classes in the world, specifically that of the ObstacleSpawner so it can populate the Spawner pointer with the live running ObstacleSpawner’s address and can then communicate with it. It could not be determined in the property window of the EaglePawn’s blueprinted properties because it doesn’t yet exist at the time you are setting properties.
An alternative approach is to have the EaglePawn spawn the ObstacleSpawner at start up rather than dropping it in the world. Edit: Then EaglePawn will automatically have a pointer to ObstacleSpawner.
In either case, the only way I know to do that is to have the ObstacleSpawner base class in C++. I’ve just always done it that way. I don’t drop blueprint classes in the world if I want to communicate with them, they are subclassed from a C++ class. Don’t know if that is necessary, it’s just how I do it so I can access any public variables they may have. You can’t access the variables even if public of a pure blueprint class.
Yes, the EaglePawn creates a pointer to a newly generated ObstacleSpawner at runtime. This worked fine when I had just the single UPROPERTY of a single FenceTemplate (rather than an array.)
My goal is to convert the singular FenceTemplate from a single TSubclassOf<class AFenceObstacle*> to a set of multiple templates. If I absolutely have to, I can just declare each singular UPROPERTY individually, but I was hoping to put them all in one slot in case I decided later to adjust the number of possible fence meshes.
Since it’s obtaining the address of a blueprint that is already instantiated as or prior to an independent pawn, it’s beyond my knowledge how you would do it that way. I wouldn’t know why it would work with a single pointer in the first place so I’m obviously going to be of no help. Sorry perhaps I should not have posted, just telling you how I establish an array of pointers for independent classes I need to reference.
It’s a tough call whether to answer a post not getting responses when you may or may not be able to help. Good luck.
You can’t do this no. If you wanted to reference an object that exists in a level in an asset, you would have to refer to it via a soft object path and attempt to “get” it when using it. This is massively prone to error however.
Assets generally have no business refering to in-world objects. Those objects don’t exist until you load the level, and the asset would break should you use it in any other context. If you move or change that object, the reference would also be stale.
Yeah, you definitely should not do this. Pawn does not exist in the world automatically, and that’s why you can’t reference something in a level inside it and have it ‘stick’.
It doesn’t sound like there’s any reason why EaglePawn and ObstacleSpawner should directly know about each other. You say “in order to synchronize states between the player and the spawner (such as the player clicking to start the map)” … but that has absolutely nothing to do with the player or the spawner, as to whether the game is running.
If you want the spawner to only be active while there’s gameplay happening, then that is dependent on your GameMode, not on your Pawn. The player pressing a button (probably before they even have a Pawn, if it works like Unreal does by default!) should not start the spawner, the GameMode should!
You haven’t given enough information to drill down to be sure of what you’re really trying to achieve, but my guess from the context, is that when the gameplay begins, you want to enable all your spawners. To do that, you should do it in GameMode, and when Gameplay begins, use an Actor Iterator to find all of the Spawners, and inform them it’s time to begin. (also make sure that you shut them off when it’s time to end!)
(alternatively, one could have the Spawner check with the GameMode before spawning, to determine if it’s OK to spawn or not, but i would prefer not having timers running when they don’t need to be, so i would turn it on/off from gamemode)
(another alternative would be to have a single timer that is fired in GameMode that tells all the spawners ‘its time to spawn something’, but that’s a bit more dependent on your details that i don’t know)