Spawn Actor from Class spawns the actor forever

At first I thought it was my blueprints calling the function many times but then I just put it to the test on Begin Play in Level Blueprint and my actor still got spawned forever. Why would this be the case? Help please!

You mean something is spawning the actor repeatedly? Check the begin play on your actor, make sure you don’t also have a “Spawn actor from class” in there (so every time one is spawned, it spawns another one).

If not ^^ this reason above ^^… Are you using a DoOnce node etc, as it won’t persist across instances…
If so, use a Gamemode variable, or Get-All-Actors-Of-Class will tell you how many are currently spawned…

Thanks for the answers guys! The weird thing is the actor spawns fine if spawned from a key, but when spawned by another event it just spawns forever. Here is the function I use to spawn it from the Event Tick. The actor is a Rune item. Inside the Rune blueprint there’s only the logic of it being picked up with a component begin overlap, and nothing more. I don’t get why it works fine when spawned from a key. Again, it even spawns like that from the Level Blueprint.

Show us all the BPs where you call “Spawn Rune”.

^^ This ^^

Also, where is Destroyed bool being set, is it ever being toggled to false?
BTW: Overall, you probably don’t want ‘SpawnRune’ being called on ‘Tick’…
BTW2: If you spawn from another event, that event could fire endlessly too…
So you might want to use a Gate / Delay or something to refine this circuit…

The Destroyed bol is not about the Rune, but about another actor. The character breaks a stone and then the Rune is revealed inside. All this is irrelevant since this problem occurs in the Level Blueprint also with the simple code Event Begin Play -> Spawn Actor from Class and a random location in the world. I added a print string and apparently the Rune_BP spawns indeed once, but visible there are clearly more inside. So maybe there’s something about the Rune itself, however I can’t seem to find anything weird about it. Also, how come when the villager drops the rune by pressing a key it’s only one?

Either use the Scene Outlier or as franktech suggested use “Get All Actors of Class” to see how many Runes there really are.

Hmm, this is very weird. So the code runs only once but spawns multiple Runes for no reason. I am very stuck with this one. Gotta hate when something really simple becomes really complicated.

I highly doubt it… :stuck_out_tongue: :smiley:

There’s probably enough clues above already to figure it out… Some assumption you’re overlooking.
Be sure to keep a copy of this project. In 1-6 months you’ll kick yourself, but it’ll deepen your learning!

My mindset is to always blame my code but the fact that I can spawn from key just fine but not from anywhere else gives me mixed signals. The rune bp is empty. Has no relevant code what soever. So spawning it from the game mode, level blueprint should be just fine just like spawning it from key. But no. Redid the Rune BP and it works. Spent more time debugging than redoing it.


You should follow through on this… Investigate further…

Keeping good notes / comments / taking a break and going back sometimes makes it all so clear… :stuck_out_tongue: You realize that you never actually showed the code that calls ‘SpawnRune’, right? This is the most important code of all… :stuck_out_tongue: If SpawnRune itself is called on Tick, or something that’s invoked from Tick, or part of a BeginOverlapEvent etc, these will all fire multiple times. This is the big difference between a keypress firing and another type of event. A keypress is only a single event, it doesn’t repeat unless you code for that.

Is there anything related to timing / dependencies at work here too? That would be different in a user keypress versus the Event-code that you didn’t show… These are all assumptions you need to nail to avoid ‘mixed signals’. For example a keypress may happen later in the chain after some prep-code has already executed. What you need to do is become more confident at predicting what your code will do and watch out for unhelpful assumptions. For example, look at where the Destroy-Actor in positioned in the Rune_BP above. Does the SpawnEmitter ever get called? :wink:

Thanks for the input franktech. Really appreciated.

I took a break, worked on some other things and debugged a little more now. The problem is deeper and is somehow connected to my client, as only clients see more runes than there really are. I fear there is something wrong with the way I set up the player spawning as I really had a hard time doing it the way I need it, and it may have broke some things.

This area of player controller is really foggy to me and I have postponed some tasks related just because I can’t seem to figure it out. If you could help me that would be great.

In my game the Host plays as a Vampire and the 4 Clients play as Villagers. I feel the way I make them spawn this is way is a little wrong, you tell me.

In my Player Controller on Event Begin Play I call for an event in the Game Mode. As I type this I remembered that the Game Mode cannot be accessed by clients, however this is how it works now.

In the Game Mode I have the logic to spawn the host as a Vampire in a desired location (so not from a spawn point because I couldn’t get this to work) and the clients as villagers.

The reason I believe there is something wrong is that I also can’t seem to make the correct HUDS appear for each individual player (the vampire should have his own, for example).

I would really love it if you could point me in the right direction as this is the only big issue that still lingers in my project.

Thanks a lot!

Alright, finally managed to spawn the correct huds from the player controller. You can do so much in so many places that sometimes you don’t know where it’s the right place to do it.

The rune is still a problem on client. I have no more ideas for it :frowning:

Where is the Rune code invoked?

I can spawn the actor from anywhere and the client sees it many times. I mean a lousy spawn on begin play, not something with variables and more complicated stuff.

How do you expect advice when you don’t show the SpawnRune code being called?! :stuck_out_tongue:

Pff, figured it out. Originally the pink nodes were swapped and when the villager overlapped the rune it first set his status as HasRune and then tried to destroy the actor. But becasue there is that branch that runs the code only if he is not having a rune I guess the Destroyed Actor never got called. Except, everything else was called, even a print string at the end. It’s like for the destroyed actor the switch was instant but for the rest it was not.

Very weird. So freakin happy I fixed this. Thanks for the help franktech! you kept me going, digging and digging.