Get transform of component from spawn actor

Hi, i’m working on a level blueprint to spawn actors “parts of level made inside blueprints”. Those parts have Arrow components to know the start point and the end point of the blueprint mesh in order to spawn others on the end of others entrances to make a custom thematic map. The problem i have at the moment is if I make a function in the level blueprint in ordr to make it easy to work or make it work random i cant get acces to the spawned actor Arrow component. How sould i proced in orther to acces the component of the actor ?


You probably need to cast the actor to its own class, after the spawn, to access the arrow component.

The way things compile right now, the “class” that is spawned is a variable, fed in by the function parameter…that means the code doesn’t quite “know for sure” WHICH class the spawned actor actually is, since it’s ambiguous in the code. So, add a “cast to” node and then the compiler will know it needs to treat things after that as your custom actor type.

Hi, @blankslatejoe
Which type of cast would be better to use? and where should i put it, im not used to use casts and i tryed and i didn´t have any results.

well, casting is basically a promise to the engine. The engine isn’t sure what you’ve spawned with that SpawnActor node. That’s because you feed a dynamic “Class” into it. So casting afterwards says: “Hey…check if you just spawned this kind of actor. If so, we can use specific things in that class.”.

So, what blueprint class of yours has that arrow component that you need? That’s what you need to tell the engine it is. You usually, but not always, want it RIGHT after the spawn. So drag off of the arrow pointing out from the spawn actor node and type “Cast to” in the search bar. Now you’ll need to scroll down to the class you want.

Actually, looking at your first post…its a little tough to tell what you’re going for though or what your experience level is–since “arrow component” isn’t something you can spawn directly (components are…well…components of actors.,.and aren’t actors themselves). You can spawn blueprints that HAVE arrow components in them though…so that might be where your problem is. Create a new blueprint with an arrow component and try and spawn that instead. Depending on how you do it you might not even need to do any casting.

1- Assume you have a Spawner blueprint class. This class make numbers of SpawnActors at runtime. Each Actor has a “Public Blueprint variable” named ID, which will assign to a number at “Spawn” time. Also, this class continuously generate random numbers on Tick and assign it to its public variable which is ID.
So in short, it Spawn couple of Actors with ID and has a random number generator on Tick event.

2- You need to add this class (spawner) to stage from editor. It should be there before running game.
3- In Actor class (which you re going to spawn), you need to use “Get All Actors of Class” on Tick and get your Spawner blueprint and put result in an array. It will be just one because you add just one spawner to stage. From that array simply get the first element and easy use public variable of your Spawner which is ID,.

you can use this in scenario like, if that random number match with the ID of you Actor, then you can play some functions thou.

In this approach you don’t need to use ANY event dispatcher.