Thanks. I’m wondering if maybe I used too trivial of an example with the cube. It’s not so much about things not being mutable, it’s about triggering logic on spawn.
-
if your cube color is the only variable, but you want to trigger logic on the client only the first time that color changes - then you have to add that extra code I was talking about. You want to change the color multiple times (mutable), but you only want specific logic to happen on the first RepNotify. Pain in the butt. I see this as a problem every designer is going to have if I present this as a solution, or they’ll just forget to not manually add guards.
-
Beyond the cube example - say you have an actor with 5+ variables to set on spawn, that means 5+ different repnotify callbacks trigger and you have no ordering to them and no confirmation that other variables have been set too. In the scope of a repnotify call, it has nothing to do with “spawning” and in code or in blueprint, you have no way of checking “Is This Spawning”.
RepNotify is called anytime that single variable has been modified by the server, there’s no context to it. That’s problematic to me but maybe I’m missing something about RepNotify that allows all of them to trigger together somehow. The problem becomes more challenging too if you have 2 values that rely on each other being set prior to triggering some kind of other event. So both repnotifies would need manual code done to check if the other values are present in some combination. -
A potentially larger problem I’m curious of is if “RepNotify” is guaranteed to send a variable with the spawn data in the same frame, but I haven’t dug that far under the hood in the ActorChannel.
For example, you spawn a cube and set the color in the same frame on the server. Will RepNotify trigger the color change on the same frame it spawns on the replicated clients? Is it possible a cube spawns on the client, and the server has decided to put the color change in a different packet or the client executes the RepNotify on a different frame than spawn? That’s more troubling than the rest in my mind and I need to dig deeper on it. I can’t have things spawning without parameters guaranteed to be there.
Sidenote: Yes OnConstruction is called for replicated actors (at least the debugger triggered on my blueprints for a client on it). Though, like I said, variables are not replicated at that stage. So you attempted to get/use a variable in OnConstruction that’s replicated, expect problems and potentially crashes which is how I landed here.