How do you play an animation in the UI when the trigger is in another blueprint? - unreal-engine4

I am a beginner with unreal engine. My end goal is to play an animation in the user interface that makes the word "coin" move. I have a blueprint called "BP_Coin" which spawns coins that the player can pick up and have it added to their total. When the coin is picked up, I can't get the animation of the "coin" text to play. The animation is in the widget blueprint called UIWidget.
I assume casting is my only issue, but am I doing this inefficiently? What's the easiest way to accomplish something like this?
I've followed a tutorial that mentions creating a reference with a game instance class and using that in the object slot of the CastTo, but I was unsuccessful. It would always come up with "cast failed".

There should be a CreateWidget node (documentation) somewhere in your blueprints in order to even display widget on player's screen. You may pass output of that node into CastToUIWidget function to achive what you probably need.
Hope that answers you question.

Related

Attaching MonoBehaviour to a Unity Tile

Is there any way to attach a MonoBehaviour to a tile in Unity, so that every time I place the tile in the scene, it acts like a GameObject with that script?
I went through all of the tile documentation for Unity, and many pages of StackOverflow, but none have an answer that helps me. Also, I know what the Tile class is, that doesn't work with my needs, I just need to know if there's a way to put a MonoBahaviour on a Tile.
"Tiles" are not game objects. So unfortunately you can't "attach" anything to them!
It's possible this example could help
https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles.html
https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles-Example.html?_ga=2.185515305.1216993433.1582538590-1535974129.1582538590
ANOTHER IDEA is you could sit a game object (perhaps an invisible one) ON each and every tile.
(Just do that programmatically, with a loop.)
That invisible game object would "be the actual thing", it would do everything. (Your logic, perhaps clicking, whatever it is you are doing.)

Why when I drag something using IDragHandler IPointerEnterHandler not always working on another object?

I'm trying to implement drag and drop using unity's EventSystem. When I start drag one object using IDragHandler - IPointerEnterHandler on another object doesn't works from time to time. Does someone know how to solve this? Or maybe someone know the reason why this restriction existing?
Since EventSystem works with raycasting, there may be another object which blocks the ray. So, you should make sure there is no other object that may block raycasts.
If you are using dragging for UI elements you can change other objects CanvasGroup to canvasGroup.blocksRaycast = false or you can set it as lastSibling https://docs.unity3d.com/ScriptReference/Transform.SetAsLastSibling.html.
If you are doing it with gameObjects you can change your object's layer to something higher from others. Such as 10. But do not forget to make it default again when you are done with it.
If you can share a gif or something else, it would be easier to help you.

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.

How to do a Unity drop and drag unit

I have my prefabs for my characters but I'm lost wondering how am I able to do a drop-able unit like Clash Of Clans. I'm almost done with the game i'm making does anyone have an idea or suggestion to do it? source code or tutorial will be highly appreciated!
just like items in an inventory
instantiate your prefab on touch.
you can either iterate through a loop and keep instantiating until your out of troops,
or
you can use a bool and an update method, to spawn one unit at your touch/mouse down,
move its position to mouse/touch position in update, as long as still touching,
finally in your mouse/touch up you stop updating his position manual and release him.
if you would like some help with the code for either implementation let me know!

Switch turns between the Player and AI in Unity

I've recently started using Unity for a resource management stealth game. The stealth part is turn based, similar to Hitman Go. I have a simple character controller and a simple patrolling AI over a specific path. However, these movements work in real time and I want to change that to turn based. The AI should wait for the player to finish his/her move and then move itself. The same goes for the player.
Both the player and AI should be able to move to their adjacent waypoints only when the movement of the other part is complete.
How should I go about that?
Thank you
The language that I'm writing in is UnityScript.
As a very simple solution, firstly you can create an empty gameobject. Name it as TurnController. With a simple script you can add a boolean variable on it. Lets name it as isPlayerTurn. For player movement you can check this, if it is true player can move. At the end of his/her move (maybe clicking end turn button or when it reachs the max distance to move or something else) you can set isPlayerTurn false. Ofcourse AI should check (Maybe in Update function. But can change by your design) if it is true, AI can do what it needs to do. And at the finish of its turn, it should change isPlayerTurn back to true. I know it is a very simple solution but hope it helps for begining. And I hope I didnt misunderstand your question.
Write the ai as a player instance and have it emulate player input.
(Instead you could also implement a common interface on both classes.)
Spawn a game object with a GameManager behaviour script that stores a reference to the current player (or ai). Then have the GameManager update the current player every frame by checking their input. If the (human) player gives input while it is not his turn, his input will just be ignored.
This way, the player and ai do not have to know if it is their turn.