I have a player with a few parts (arms, hands, weapon) and whenever the player changes move mode (running, standing, aiming), all actions on these parts are removed and new ones are run.
Now, when the player is firing, i run a "shooting" action on the weapon node, and when the player stops firing, i run weapon.removeAction(forKey: "shooting")
The problem is: this "shooting" action obviously gets removed when the player changes move mode (as the weapon's actions are all removed).
Is there any way to remove all actions EXCEPT (forKey: "shooting") ?
I tried giving all other actions the key "moving", but quickly realized that multiple actions cannot have the same key (it overrides the previous action with that key and that previous action is never run). (any fix for this btw? just curious)
the obvious solution is to run the "shooting" action on a separate node from weapon, but that would be less elegant.
Personally, I would add a Gun Node to your sprite, and put the shooting action on that node so that you could remove all actions
There is no way to enumerate over all your actions, you can remove by key, or remove all, that is it.
If you extract your action, remove all, then add it back it, it will restart your action, which you also do not want.
Related
enter image description hereso im basically new to blueprints and i am trying to make a game based on collecting trophies and i finished the code, but for some reason when i drag and drop the trophy it disappears, that wasnt an issue before, im also trying to randomize where the object spawns and i was succesful but after i made changes to the trophy code, suddenly it wont spawn at all, here are some screen shots. enter image description here
As I see you are destroying object on overlap, right before you respawn the object, you should destroy the trophy only after you spawn new, so destroy function must be called at the end, when other logic is finished.
And the best way to handle such operations is some kind of manager. You may use game mode, level, player controller as trophy manager, anything that will exist from the beggining of play and till the level is closed.
I am a begginer in ue4 blueprints system. I've wanted to create simple code: player enter the trigger box, and press E, after that text should appear on the screen. What I did wrong in my code?
I'm no expert, but I think you should use a branch node to check if the key is pressed. No harm in also changing your other character to a getplacyercharater.
Best of luck :)
On Component Begin Overlap (Box) fires on the frame you begin overlapping. Unless you pressed E on the same frame you begin overlapping, this will not work.
For this to work, you would have had to be checking if it was overlapping and for the key press on every tick. Don't do that, it's a waste of time.
What you could do instead is On Component Begin Overlap, set a variable to record that you're ready to interact, and then check for that variable when you press E.
This is something I did recently using the Top Down template that demonstrates 'move within distance of object, press button, thing happen'
Adding an object to a 'ready to interact' array on overlap in Player Character.
Detecting a mouse click, checking if it was in the array, doing stuff in Player Controller.
It sounds like you're building an interaction system though, so if you want this to be as re-usable as possible you should probably have this code on your Player Character / Player Controller, and not in the object you're interacting with.
We have an unusual use case. Let's say you have 2 objects that is touching. This will trigger OnCollisionEnter. Now we change ownership of one of them (It's a multiplayer VR game). Now we need to also assign ownership to all touching items to get local physics to look nice.
The naive brute force way would be to use OnCollisionStay and do the ownership check every frame. But its naive and increased frame time.
There must be a way of "resetting" the objects collision when taking ownership, so the OnCollisionEnter triggers again for all items it touches?
Maybe track all items currently touching an item in a list.
Add new item in OnCollisionEnter.
Remove item in OnCollisionExit.
Then you can loop thorugh all currently touching items to change the owner
I am making an IOS game in Swift with Spritekit, I have a player Sprite which I want to rotate and move towards where a touch is on the screen. Currently I get the angle, Create the action to turn, Run the action and do the same for the movement. This works well for a single touch, However I now want to do the same when a touch moves. First I tried removing the action then running the new one, The sprite jitters or does not move at all, because the action is being cancelled very soon after being created. I have also tried running it every 100ms however I still do not get smooth movement.
So I was wondering is there any way to modify an action as it is running? Or what is the right way of doing this?
You can override the didEvaluateActions method in your scene class, this gets called after all actions are performed in an update frame. In that method, destroy the old action and start your new action. If you are still seeing jitters, then you need to reevaluate when you want to be removing actions
This may not be an issue, but it sorta defy the purpose of having prefabs.
I have a prefab; then for various reasons, I did modify it. What I usually do is to drag the prefab in the scene, modify it and click the apply button to save the changes.
I did duplicate few times this prefab, modified one and did press apply button. Then I realized that all the other duplicates did not update accordingly.
Even the prefab itself, didn't update at all; I had to drag and drop the modified prefab on top of the original prefab icon to get that changed.
I do remember that in the past; each prefab would propagate changes, every time you modify one; and also, I recall that every time that you modify a prefab, you would get the warning, telling you that you are breaking the prefab. Which didn't even happen.
Did the prefab behavior changed recently? I didn't touch Unity since V3.0, so I may have missed some change in the editor, now that I am using 5.3.
I did 2 tests. The first one was:
I instantiated a prefab
Changed an attribute
Applied
My first result was the propragation working fine.
My second one was:
I instantiated a prefab
Added an child GameObject
Applied
This one still propragated.
So is working fine on version 5.3.4f