Download

Sending tags instead of actors

I read somewhere that attaching a unique tag to each actor and using ‘get all actors of class with tag’ to reference it is better memory management than storing a hard reference of this actor everywhere you need it, and that its also easier to send the tag ,rather than the actor, over a network and have the receiving client/server ‘get all actors of class with tag’ to reference it.

I’m creating a building system for my game and expect upwards of 300 building actors to be in my level at any moment, which all need to, rarely, reference to a playercontroller, playercharacter, etc. Would the system above be beneficial to me and is this the best way to go about limiting the amount of data sent over a network?

Hi, I don’t see any memory cost for storing pointer to an actor. And GetAllActorsOfClassWithTag is a slow operation, so no I would not go that way.

And as you mention hard reference, everything an asset hard references (like an object reference or class reference) will be loaded into memory as soon as that asset is loaded into memory (so if you never kept that in mind when buiding your logic, you may end up having everything loaded all the time). But GetAllActorsOfClassWithTag will also result in a hard reference to that class, it will be loaded into memory so no difference there. Ofc you could use soft references to avoid that.

and is this the best way to go about limiting the amount of data sent over a network?

If you worry about network bandwidth, you can use the network profiler to see what has highest bandwidth usage and optimize from that.

1 Like

Hard references don’t load anything extra into memory? Its just a pointer to the actor that’s already been loaded into memory?

Yes, it does.

Understand @chrudimer meant something like this.

For further reference: starting at 15:30 → Demystifying Soft Object References | Inside Unreal - YouTube

I’ve watched that which is why I’m confused. Does the hard reference load the actor into memory another time separate from the actor that’s in the level, or does it just get a pointer to the actor? The video makes it sound like the reference loads it in again, but the reply to my question makes it sound like its only a pointer to the actor.

No. You add the blueprint to level, and everything associated with it will be loaded as well.

At 18:24

A hard object reference is you’re essentially attaching the object to your blueprint … and when the blueprint is accessed, the object is loaded.

Pointers do not load or create a new instances. What I understand @chrudimer suggested is as you add your blueprints to the level, simultaneously create their respective pointers. It’s easier to go through that than loop through all actors looking for tags.

Definitely just use references, this is basically never going to create any memory issue in practice. And finding actors by tag is a very expensive operation. As for network, actor references are fine to send over the network for replicated actors, but sometimes you may need a reference to an actor that isn’t replicated - in those cases you can use tags.

1 Like

Unless Im grossly mistaken, the example you provided (300 buildings referencing a player controller, etc) wont be an issue, since theyd all be referencing the same player controller?