I’m wondering how I can spawn only one instance of a Blueprint at a time, ie. when a second instance of the same blueprint is spawned, the previous instance will be automatically destroyed.
For reference I’m spawning the blueprint from a radial menu as demonstrated below:
I’m wondering how I can spawn only one instance of a Blueprint at a time, ie. when a second instance of the same blueprint is spawned, the previous instance will be automatically destroyed.
As above, it would be close to something along the lines of:
Apologies for the low resolution images, the help is much appreciated.
There’s only one actor (campfire 1) which is being referenced by both the variable and the spawn actor node. Is this what you mean or am I missing something?
Just wanted to make it clear that for this to work, the actor has to be spawned from this event or a copy of the reference already stored in this variable:
Ah I see, sorry I should’ve clarified. The second actor being spawned is assigned to another slot in the radial menu (which is based on an integer value). Unless I’m mistaken, the spawn campfire logic is self contained and is not referenced anywhere else, neither does the logic for the ‘spawn actor 1’ overlap with ‘spawn actor 2’.
You have to hold the reference to the campfire outside of the campfire itself, else it would be a selfdestruction , potentially.
The best place to hold this kind of things is the GameMode or even better the GameState class of the game.
The GameState normally has all current information of your current game and is even replicated in the network. The GameMode is the manager of your game and provides important game functionality, like spawning your campfire.
So the (imho) correct thing would be:
PlayerController calls the “PleaseCreateCampfire” method on the GameMode
GameMode checks in GameState if there is already a Campfire reference
If yes the GameMode destroys the reference and creates a new one
Just noticed that what you suggested does work, however only when the character doesn’t move.
The spawn location is based on the player’s location and when the character doesn’t move, only one instance is called. However moving even slightly will call a new blueprint without deleting the old one.
It’s been a while since I looked under the hood of the Spawn Actor from Class node - specifically the behaviour of the collision override.
Can’t recall if Default still equals Ignore collison but try setting it to Always Spawn (or smth named like that). I’m thinking that the char movement component’s capsule’s collison handling may interfere here somehow.
Right I see, this took a different direction than I was expecting haha thanks for all the help, I’ll keep messing around and report back if I fix it. Thanks again!