So I was trying to get an actor by its tag in a BeginPlay function on another object. The tag is already set in the level and it is the correct one because I can get it to successfully find it but, for some reason there has to be a 0.5 second delay before it will detect the object in question. Is there a reason this might happen? Any help would be greatly appreciated.
It really depends on your setup. How many actors in the level, how much code you’re running etc. But when you start to load the system, you will find at some point you have to wait for things like other BPs to finish initialising.
If you want to be sure you’re going to get what you want, the only way is to take the code away from BeginPlay and put is on a custom event that you call when you know everything’s ready.
To be honest, I’ve never seen it happen with tagged actors, but could it be that you have some sort of chain of events that make it ‘look like’ the actor isn’t ready, but actually something else is happening?
Are you mixing “Actor Tags” and “Component Tags”? These are two different things. Try it with getAllActorsOf class and compare the number. Other possible workaround is after getAllActorsOfClass make a forEachLoop of that Return Array and check these for a tag.
I guess I just assumed that since the object I’m looking for is in the scene already with the tag that it would be able to find it at the start of the program. But maybe if it hasn’t finished its own BeginPlay function than it wouldn’t be found with the tag look up.
Is it just an actor with a tag, or is it some kind of BP? ( the thing that shows late )
Whats wrong with the answer that it get’s a downvote without a comment?
It is a BP actor with some functionality in it but, the odd thing is that there isn’t really anything happening in it on BeginPlay that would take it that long to initialize but, if I throw just an empty actor into the scene and look up its tag it doesn’t need the delay. So I’m not sure but, I’ll probably reorganize this functionality so that it doesn’t happen on BeginPlay and instead control it long after everything has been initialized.
I can find the tag in question, the problem is not that I can’t find the tag but that for some reason I have to add in a delay node before I can find the tag.