Why doesn't "spawn actor from class" execute more than once, while using a "for loop" and "select node" - unreal-engine4

I am using Unreal Engine 4's visual blueprint scripting language to make a shotgun in my game. When I call the function fire, it simply spawns an actor at a given location (this actor moves like a bullet, and has a collision mesh). The only problem is when I want to add another "spawn actor from class" node to the event graph, both of the nodes stop working, and nothing happens. I tested to see if my for loop, select node combination was messing up, but it worked and printed out everything fine, but for some reason when the "spawn actor from class" node is put in more than once, it stops functioning.
Here are pictures provided, if you needed them, and feel free to ask any additional questions.
Here is the Imgur link: https://imgur.com/a/2ggqoAW
Can anyone please help me with this problem
Thank You.

As was stated in a comment, you should never use a for-loop in this way. Just use sequence node if you want to execute stuff in order. In your case, looping over the different transformations would be even better.
Also, don't use actors for projectiles. Actors are pretty heavy objects which require a lot of resources to create and maintain by the engine. A few hundred actors each ticking every frame can easily tank your framerate. Create a custom component and maybe have a look at UProjectileMovementComponent or EPIC's shooter tutorial project.
As for your current problem, check the collision handling, they might not spawn because they overlap when spawned.

Related

Instantiating Objects at Different Intervals Unity

I am trying to make a 3D jumping game where my character is standing still and the objects and background are moving towards him to make it seem like he is running. I have a bunch of models for buildings that I am instantiating using an empty game object that I use as a spawner. I want the buildings to spawn one after each other, so whenever one building has moved far enough and left enough space the next one should spawn. I first tried to do this with InvokeRepeating, but the buildings are different widths so it does not work well with a constant repeat rate. I then tried to put a collider on my spawner and spawn a building whenever the spawner collider is not colliding with anything, but it seems to just spawn buildings infinitely. Is there a way to fix this or a better way to do this?
There are many different ways of doing this.
The most straightforward is possibly to let each building spawn the next one, as I assume they each know how wide they are and thus when it's time for the next.
Well , first things first your problem is looking more like a design problem. I would recommend searching things like "procedural world building" , also object pooling. There is lots of examples of runner games that do what you describe.
You can check the palyer position to instantiate , you can create parts of the road as prefabs , make lots and lots of prefabs and instantiate them as you go etc. The question you asked is simply too wide to give an actual answer. So if you have any more spesific questions , it'll be nice to answer !

My unrealengine lags when placing actors for world generation

I want to make world generation sort of like minecraft with destructable environment, but even one layer of blocks makes my game lag a lot, so i would like to know if there is anyway i can reduce or prevent the lag. Or any alternative ways to creating world gen that doesn't lag that much.
My level blueprint that makes the world gen looks like this:
(I couldn't fit it in one screenshot but the print string is the same in both pictures)
The cube actor which is spawning currently has no code but since i want a destrucable environment it will have code latter.
I have attepted to use voxel instead but it says im missing a .dll file, which im not sure what to do about. Where in the computer should i put that file?
The image here is in danish, but it says that the program could not be started, because VCRUNTIME140_1.dll is missing on the computer. Try to reinstall the program to fix the problem.
Thanks for the help
The game lags after you spawn or only while spawning the objects? consider using code instead of blueprints, usually you have better performances.
Use hierarchical instanced static meshes instead actors!
More details: YouTube

Controlling NPCs throughout the plot line of a game

I'm trying to figure out a good way to script the NPCs in my RPG. A sample NPC interaction could go something like this:
NPC starts dialog #1 with player.
When the dialog is finished, the NPC moves to a waypoint on the map.
Once the NPC arrives at the waypoint and the player talks to him again, he starts dialog #2.
At the end of the dialog, the NPC asks a question.
If the player gives response A, the dialog ends. In this case, talking to the NPC again starts dialog #2 again.
If the player gives response B, the NPC gives an item to the player, and disappears. From now on, that same NPC will be present in a different Unity scene.
I've found plenty of examples of making a dialog tree, but I can't find a good way to handle complex situations like that. One of the most challenging problems is to determine which scene -- and where in the scene -- that NPC is. Depending on how far along the player is in the game, that NPC could be in any one of many different scenes, and will have different dialog and behavior.
Since Unity makes it easy to attach a script to my NPC's game object, I could of course do this all through a C# script. However, that script will get pretty big and messy for important NPCs.
The path that I've gone down so far is to create an XML file. Something like this:
<AgentAi>
<ActionGroup>
<Dialog>
<Statement>Hi!</Statement>
<Statement>Follow me.</Statement>
</Dialog>
<MoveTo>Waypoint_1</MoveTo>
<SetNpcState>NpcGreetedPlayer</SetNpcState>
</ActionGroup>
<ActionGroup>
<Conditions>
<State>NpcGreetedPlayer</State>
</Conditions>
<Dialog>
<Statement>Here, take this.</Statement>
</Dialog>
<AddItem>Dagger</AddItem>
<MoveTo>Waypoint_2</MoveTo>
</ActionGroup>
</AgentAi>
That sample would cause the NPC to greet the player and move to another spot. Then when the player talks to him again, the NPC will give the player a dagger and move to another waypoint.
The problem with the XML is that I'm worried about it growing very large for important NPC that can be in a lot of different places depending on where the player is in the game. I'd have to keep dynamically determining which NPCs are in a scene each time I load a new scene. I'm not totally against doing it with XML like this, but I don't want to waste a bunch of time heading down this road if there's a better way of doing it.
Since this type of behavior is common in a lot of games, is there a good way of doing it in Unity without having to homebrew my own complex system?
Normal software systems would use a database, once the level of complexity gets too high.
I'd setup the storyline with a numeric reference, like the pages of a book.
If they go to a higher number without interacting then the interaction is still available.
Then you can setup each interaction as a separate thing, with a start and finish number (not available before and not available after).
maybe you could do this by making the xml files separate, but I'd think you still need to tie them into the storyline.

How to apply animation to a large number of static mesh actors in a single blueprint? UE4

I'm working on a project in Unreal Engine 4 where I receive all the static meshes and objects from the designer classified and named correctly, for example she sends me a TV Unit and I want to find all the cabinets in this TV unit and apply the open and close animation to them.
What I tried to do so far is that I was able to detect all the cabinet doors in the TV unit in the level blueprint, based on the names of objects I received, which I already know is a bad idea but bear with me just for the sake of debugging, and I tried to apply the animation when that specific object is overlapped.
The problem is I can't seem to find a way to make the overlap event to work on all of these objects in the foreachloop, how can I attach the event to all of these object? and what is the best practice for something like this?
My level bluprint
Your question is not clear but here it goes:
Remember! A for loop will always bind the event to all elements in the array but if you take the element from the loop and use it in your event only the last one will be used.
Also I did not understand how can you play an animation on a static mesh , you will need skeletal meshes.
Please follow up to my answer , lets fix this . thanks.

Save/Load scene state for NPC actors

All of the examples that I've seen of saving/loading a scene in Unity are either only saving/loading simple data (like the player's current health and position), or they're using a purchasable asset from the Unity store. The logic I need is a little more complex than having just a few predefined character parameters to save, and I'd rather learn the proper way to do this instead of buying a Unity store asset, so I'm asking here.
My scenes have some actors (NPCs and enemies) that are defined in the scene in the Unity editor, and some actors that are dynamically added via script during run-time. When the player saves, I want to record the current position/state/etc. of each actor, and then restore those actors to their last states when the player loads the game.
For the actors that defined in the Unity scene in the editor, I'll have to be able to look up the corresponding actor's data within my persisted data, and reapply that state to the actor. One of my main struggles here is being able to identify which set of data goes to which actor, since the actors in the Unity scene often just have generic names (like goblin) so there's no way to tell instance A from instance B. I thought about doing something like creating a PersistentData object that I can assign to each actor, and have the PersistentData object generate unique GUIDs for each actor. But for something as common as saving/loading scene state, I don't want to write a bunch of custom logic if there's already something built in that'll do what I want.
The second problem I'm having is that for actors that were dynamically added to the scene, I'll have to write some code to recreate them after loading the scene. Again, if there's already a built-in or accepted way of doing this, I don't want to write a bunch of code and reinvent a bad facsimile of an existing wheel.
My actors are all derived from MonoBehaviour, so I can't serialize them directly.
Is there an existing way within Unity to do this, or is there a commonly accepted way of handing this scenario?