Help! Actor Component On Begin Play re-running!

So I have a Player Character.

I’ve made an Actor Component with a struct of various attributes (strength, health, mana, etc). That Actor Component is a child of the Player Character.

I’ve noticed (through prints/breakpoints/etc) that if I change ANY data on the child actor component (for example, I change a float for one of the attributes), then On Begin Play event for that actor component seems to fire off again. This was discovered because I was setting the attribute “Current Health” to equal “Health” at the start of the game. If I changed any value (including the health) it would automatically reset it back to the default values agian.

I’ve also noticed that another actor component (child of the same character) ALSO re-runs if data is changed on either of the components and vice-versa.

Anyone know what’s going on here?

Your struct of various attributes (strength, health, mana, etc) should be in the Player State class.

Ok, but why is the Actor Component Event Begin Play re-running?

EDIT: So I moved them to a new PlayerState BP, but when I change it there, using Construction instead it still happens - changes just get overriden.

Because construction is running on server and then on client.


Only the server (Authority) should make the change. You need to apply flow logic to prevent the client from making changes.

Switch has Auth (authority), OR branch w/is server?, is dedicated server…Or use network role checks.

Thanks so far, so even if I’m just running as a standalone, it will still run the on construct?

Yes.

  • The server will spawn an instance → Execute Construction → Execute Begin Play.
  • The client will spawn an instance → Execute Construction → Execute Begin Play.

If you want only one of the proxies (Autonomous, Authority, Simulated) to execute a chain of logic you need to specify it with flow control.