Unreal How to make my static mesh undestroyable in run-time unreal? - unreal-engine4

I created unreal game and it have a option that can select objects that you need to place on the floor from a widget menu. And it also have a option to remove the objects that placed on the floor when pressed "R" key. My problem is when I place my tracer on the floor and press "R" it also remove the floor and then character start to falling down. So, anyone no how to remove only selected objects and not everything in the game.

I think that you should create a new class (C++/Blueprint) for your 'destructible' static meshes. Then while tracing you could try to cast the object you're pointing at to newly created class and if casting is successful, destroy it.

You can either use "Actor has tag", but then you'll need to add the tag on each individual actor you want to affect.
You can edit channels in the Project settings -> Collision, make a new channel specific to things you want to affect, and then change the collision settings on the actors and on the linetrace.

Related

How to create a custom height snapping tool in Unity Editor

I am making a strategy game and I need to have a tool which places the objects above the terrain while I am dragging them in Unity Editor when I work on level design.
Basically I want to get result like here:
https://www.youtube.com/watch?v=YI6F1x4pzpg
but I need it to work before I hit the Play button in Unity Editor.
Here is a tutorial
https://www.youtube.com/watch?v=gLtjPxQxJPk
where the author of it made a tool which snaps the object to the terrain height when a key is pressed. I need the same to happen automatically whenever I place an object over my terrain. And I want my tool to adjust the Y position of the object automatically even while I am dragging it inside of the editor.
Also just to clarify: I don't need grid snapping and I don't need this functionality during the gameplay. I just need to have a tool for my level design work.
Please give me a clue where to start with it.
Thanks!
There is this tag you can apply to classes so they do call their regular events during editor mode already: https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html
A trivial way then would be to apply this to a special class/object which regularly "finds" all objects from the game object hierarchy. Then it shall filter that list for the ones you want to snap to the axis and enforce their Y.

How can I change the material of an object from a different scene with a button?

I am new to Unity and to get the hang of the program I tried making the Roll a Ball game from the unity classes and expanding it (Adding levels, a pause menu, etc.). Currently, I am trying to make a menu where you can choose the colour of the ball you control. Trying to search it on Google resulted in a dozen different solutions, none of which were of help. It would be appreciated if someone could help me out.
First you need a reference to ball GameObject (or at least his MeshRenderer component)
public GameObject ball;
Then you need to create a Menu with different buttons that correspond every button to the Material you want, simplified:
public Material newBallMaterial;
To change ball material you have to overwrite his material like this:
ball.GetComponent<MeshRenderer>().material = newBallMaterial;
As derHugo pointed, if the trully problem is to maintain the reference between scenes, try to use DontDestroyOnLoad to maintain objects between scenes. Use it like this:
DontDestroyOnLoad(gameObjectToMaintainTheReference);

is there an option in unity to hide objects, UI elements, 3d model?

I'm new to unity and i'm trying to make an AR app, animal card game.
I have one scene/one AR camera (i'm not sure if it would be better to have one scene per animal) , I have one UI button that pop up when an image target is detected and I want to make more, one for each animal but my problem is that I can only put the buttons in one place in the canvas.
I would like to know if there is somewhere an option to make my object invisible just in the editor ?
thank you.
There's two ways in which you can hide objects in the editor - its either using Layers (you can set layer visibility in the editor and distribute objects among layers.
The alternative is to use gameobject's HideFlags but its realtively more complex (and easy to lost objects in the scene).
If you want to hide objects in the gameplay, theres two ways - you either disable the whole gameobject (using gameObject.SetActive), or you disable its rendering component (using GetComponent + enabled variable. Third way exists for UI objects - that's using CanvasGroup component

How can I access an object's components from a different scene?

I have a Player gameObject that has a script on it which keeps some variables inside it. I created a scene which acts as a main menu and has "Shop" part in it, which has upgrades in it, basically I need to access Player gameObject's script from a different scene so I can modify variables from main menu scene. How can I do that ?
check this out:
https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
once your player is loaded this will keep him in every scene until you choose to release hiim, meaning when you load your menu scene he will be there to access.
now since we know hes there, we can:
(note that player is your script with the variables not your actual player)
ScriptName player = GameObject.FindObjectWithTag("yourtag").GetComponent<ScriptName>();
Be default the components are instances of a class. If there isn't a GameObject with that component in the currently loaded scenes, there is nothing to access.
If I recall you can now load more than one scene at a time.
If there is a GameObject with that script currently loaded you can use:
https://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html
or even better
use singleton design pattern, in case you have only 1 player at a time.
I guess you want to save these upgrades for the next run of the game, so you can use PlayerPrefs
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
If you want to save more than 50 values of data I would suggest using a file based DB like SQLite, it takes little time to setup and works very fast. And it is a lot more readable than using PlayerPrefs.
How about static class?
You can keep values there and access it from any place you want :D

Tracking one marker at a time vuforia

I am creating a HoloLens application with Vuforia, and i have a total of 9 markers and associated GameObjects with each marker. I want my application to show only one object at a time: for example, I scan the first marker, show the first object; when i scan the second marker, i want the first object to disappear and only the second object to show, and so on.
I tried adding a script to each GameObject that would destroy the GameObjects in the scene, but that did not work.
I have very little knowledge with C# so please point me to specific code.
Thanks all!
In order to control the maximum number of targets to be detected at the same time you need to use Vuforia's hint:
Vuforia::setHint(Vuforia::HINT_MAX_SIMULTANEOUS_IMAGE_TARGETS, <desired number>);
This is what you asked - however, according to what you wrote in the comments this is not really what you need. If your want to use extended tracking for other targets, it means they have to be detected too. So, what you really need is - once you have a target, to know if it is extended right now or not, and act accordingly.
This is done via:
if ( result.getStatus() == Vuforia::TrackableResult::EXTENDED_TRACKED )
This is an option in the Vuforia configuration.
Select your scene's ARCamera asset
Click "Open Vuforia Configuration"
Change "Max Simultaneous Tracked Images" to 1.
I saw that you mentioned this doesn't work with Extended Tracking. I haven't noticed this behavior myself, but if needed you can manually toggle the active states of the objects with GameObject.SetActive().