object in unreal engine disappear? - unreal-engine4

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.

Related

Flutter Flame & Bonfire: Instance of '' cannot be added to Instance of 'BonfireGame' because it already has a parent: Instance of 'BonfireGame'

I hoping somone can help with the following error I am getting
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Cannot find reference BonfireGameInterface in the component tree
#0 BonfireHasGameRef.gameRef (package:bonfire/util/bonfire_game_ref.dart:21:7)
Instance of 'TurnManager' cannot be added to Instance of 'BonfireGame' because it already has a
parent: Instance of 'BonfireGame'
Im currently using flutter flame engine and Bonfire. The bonfire game is embedded within the flame game. Essentially when sprite component touches an enemy component I use gameRef.overlays.add() to display the bonfire game. when the game is done i use gameRef.overlays.remove() to remove the bonfire game. The issue is the next time the play component touches an enemy component I get the above error. Any help will be greatly appreciated.
It seems when your bonfire game is displayed via overlay, some code gets executed that tries to add a TurnManager to the bonfire game. On first display, this works fine, but on subsequent display, as that TurnManager is already child of bonfire game, attempts to re-add it causes problem.
When the bonfire game is removed from the overlap, it goes into detached state, but all its children are still attached to it. To fix this problem, you'll have to just check if the TurnManager in question is already added or not. If it is already added, just skip the add call.
you need two steps for the solution
{component}.removeFromParent();
in this sentence, the child is removed in the component tree when disapear on the screen.
Otherwise, the previous child will always be tied to a parent, which does not allow him to be added to a new parent
2.You can only add the Mannager class once add({TurnManager})
but in the TurnManager, It is possible to generate multiples gameRef.add({componentes} taking into account component.removeFromParent(); always

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

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.

Problem with loading next level in Unity 3D

I have a 3D game, and I added a trigger that loads the next level with a small animation when the player goes through it. It all works fine in Unity editor, but when I build the game it does not load the next level, neither it shows the animation. Any ideas what could be wrong? Thank you!
Hard to say without more detail, but in general it boils down to one of two things. Either the trigger is not firing, or there's a problem with the script.
Try attaching something else to the trigger, maybe something that will enable a disabled GameObject in a position that would be visible when you're hitting this trigger. If that doesn't show up, that tells you the problem is with the trigger.
Otherwise, you have a script issue. The most likely cause is that you're trying to load a scene that isn't listed in the project's Build Settings. Double-check that the scene for the level you're loading is in there, or it won't get built into the project. If the call to LoadScene/LoadSceneAsync is in your script before the call that is running the animation, then if it errors out due to the scene not being available, it would never reach the point where it plays the animation, which would explain what you're seeing.

How to duplicate a live 3D object in another place in a scene?

I have built a game object in Unity that updates its appearance every time the user touches it in VR (collision). What I want is to show the replica of that object in another place in the scene so that whenever the user touches the first object, I see the second object changing in appearance as well. Is there a faster way of doing this without creating a copy of that object in the scene beforehand and changing it every time a change happens in the first object. I suppose I'm asking if Unity has a way for me to show duplicate copies of a game object in a scene without having to create them in the scene beforehand.

Having multiple unity scenes open simultaneously

I've been developing a board-style game in Unity3D. The main scene is the board, and has the data about each player and the current (randomly-generated) board stored within it.
I intend to add minigames into the game, for example when landing on a particular space on the board. Naturally, I would like to code the minigame in a separate scene. Is there a way I can do this without losing the instance of the current scene, so that the current scene's state is maintained?
Thanks in advance :)
Short answer: no, but there may be another way to do what you want.
A basic call to Application.LoadLevel call will destroy the current scene before loading the next one. This isn't what you want.
If your minigame is relatively simple, you could use Instantiate to bring in a prefab and spawn it far away from the rest of your scene. You can even use scripts to switch to another camera, toggle player controls and other interactions in the scene, and so on. Once the minigame is done, you can destroy or disable whatever you brought in, and re-enable whatever needs to be turned on in the main scene.
You could create a separate scene and call Application.LoadLevelAdditive to load that scene without destroying the current one. As above, you can then use scripts to manage which cameras and scene behaviors are active.
If you're careful, you don't really need two separate scenes. It may be enough to "fake" a scene switch.
Hard to give a complete answer without code, but you should look into the following things either with the unity documentation or youtube:
PlayerPrefs, this is one way of saving data, although i believe it isn't entirely secure i.e. being able to edit from a text file.
Serializable, this is apparently better than playerprefs.
DonDestroyOnLoad, can carry over information to multiple scenes.
Static variables, again not sure if this will help your particular problem.