My question is, how could I hide a GameObject when it is not being rendered by the camera, but to unhide it when it comes back into the camera view?
My code is the following:
void Update () {
if (renderer.isVisible) {
objectToHide.renderer.enabled = true;
}
else {
objectToHide.renderer.enabled = false;
}
}
The problem is, the object becomes hidden, so it can't be detected and unhidden.
Any help is appreciated!
(The goal is simply to speed up the FPS and improve game performance)
Your answer is simple. The game only renders the objects in camera sight. You can hide an object or even disable the renderer component but its not used for memory management or better process.
There are standard techniques for making a game run more effient. One of them is LOD or LEVEL OF DETAIL. You have a model with different polycounts and different texture resolution. When its near you use the highest polycound and highest texture resolution for further distance you use lower options.
Another technique is level streaming. If you have a big level and you want to game run on low memory or don't make players wait for long time for level loading, you have to do this. If you search a little you can find lots of information on different engines.
Most recent games have an option to choose foliage detail or environment detail. You can make a layer for every level of detail of your game and for every level of option player made you destroy those objects. Maybe I'm wrong but renderer.enable cant be good because the object still is in game and game just doesn't show it. You have to change many components to make it work and controlling all of them is hard.
To improve performance, you better try to destroy scripts and gameobjects as soon as they are not needed. Like bullets coming out of the game board, scripts that run just once and already finished, ...
Related
I'm making a first person shooter and im trying to make a reload animation.
I want to make it look like the hand grabs the mag and pulls it down.
How do I make two animations work together?
I remember having to do that for my wrestling game. What I did was create 2 controllers and 2 animations. Controllers should be the same (have same timing, transition and all that). Then make one animation for example animation of how hand reloads a gun. Now memorize sample rate and in which frame you put keys and what do they do (what do they change). Now start animating how mag is getting pulled BASED on what you have done previously. Like in what frame it should go down and in which frame it should be thrown or new one should be inserted and etc.
Then you will have to enter play mode in order to see them simultaneously. I am making a wrestling game and this method is what I use.
Good luck
https://docs.unity3d.com/Manual/AnimatorOverrideController.html
he Animator Override Controller is a type of asset which allows you to extend an existing Animator Controller
, replacing the specific animations used but otherwise retaining the original’s structure, parameters and logic.
This allows you to create multiple variants of the same basic state machine
, but with each using different sets of animations. For example, your game may have a variety of NPC types living in the world, but each type (goblin, ogre, elf, etc) has their own unique animations for walking, idling, sitting, etc.
By creating one “base” Animator Controller containing the logic for all NPC types, you could then create an override for each type and drop in their respective animation files.
Our goal is to track a target once and then have a scene be built that you can turn around and look at, without the objects moving too much (most basic example is just 6 spheres distributed over 360° around you).
Extended Tracking seems to be the tool for the job, but out of the box it is kind of unstable and shaky, and loses positions quickly when turning away from the marker/target.
Is there any approach (I'm thinking script-wise) to build upon the standard behavior and make it more robust, e.g. retain the objects at the place they were scanned first?
If you are using Image Targets to track image, then make the following changes in the script > DefaultTrackableEventHandler.cs
protected virtual void OnTrackingFound()
{
....
....
StartCoroutine(TurnOffTracking());
}
IEnumerator TurnOffTracking()
{
yield return new WaitForSeconds(2); //Keeping a delay of 2 seconds after the image has been tracked
TrackerManager.Instance.GetTracker<ObjectTracker>().Stop(); //Tracking will be stopped and the objects that have been positioned after getting tracked will be in the same position in world space
}
Make sure you do the following changes in the project:
(a) Extended tracking (device position tracker) is enabled.
(b) Set world center mode of Vuforia Behaviour in AR camera to "DEVICE".
I would recommend you try a mashup of two different components. Firstly you could use a normal target detection for the image. Then after you catch the event that the image was recognised, you would simply activate the Ground plane tracking (you can just prompt the user to look down and then tap or something similar).
The reason extended tracking doesn't work so well for you is that it is not designed to cary space tracking on its own it only remembers the image position roughly in its FOV so that different obstructions don't cause tracking issues.
Hope this helped clarify it a bit!
Hi guys i was wondering how to create a shape adjustment with two objects which specifically could be described as the independent cells, one of which is static, and the second one is dynamic and surrounded by "plasma". The movement of the active object must be controllable by the user (WSAD). Collision of the active object with the static one causes the static object to be swallen, though doesn't change it's position stays in place all the time. As the active object moves, passes the swallen object and troughts it out.
See the image below:
Player character
When it comes close enough to pink enemy it's starting to swallow it (surround by yellow thing)
Pink enemy is completely sourrounded when red circle is in the centre of both.
When it leaves enemy it takes off the yellow thing
I was wondering what is the simplest way to do it. I've been thinking about cloth, physics joints, mesh substraction (is it even possible?), some kind of animation... I don't have much time to do it. Can you show me the simplest way. Which tools and approach should i use? I'm not asking for full code or full solution only for some tips.
Tim Hunter mentioned a wonderful way, most perfect in 3D.
You can use another approach in 2D :
Inside OnCollisionEnter2D try finding hit points using Collision2D.contacts . See this reference .
Create some particle effect there.
Disable the enemy
Now play swallowing animation of the player.
At animation end, enable enemy again.
Maybe calculation is little tricky, still efficient.
I'm creating a 3v3 multiplayer game and I'm stuck on an important part before the gameplay comes in.
I was wondering how you would approach creating a Dota 2 style loading screen for loading characters into the game (Picture below).
Creating the UI isn't the problem. The problem is animating it to look clean while also having it actually load the game (terrain/gameobjects/etc) with a progress bar or something.
I load the level with this
PhotonNetwork.LoadLevel('Game');
Then a gameobject spawns each player with
PhotonNetwork.Instantiate('....');
This works pretty well with nothing in the scene other than a plane to walk on. Now I just need to create the loading screen BEFORE the character loads while actually loading the terrain/objects/etc.
If anyone could point me in the right direction I would really appreciate it.
Thank you
Dota 2 style loading screen example:
I think this is a perfect case to use for Scriptable Objects in Unity.
Because as far as i remember there are around 100 heroes in Dota 2 and only 10 of them will be picked. So the images in this loading screen would change based on player input. Therefore, you should create scriptable objects. Then you can change the image(hero) also modify/add nick names to it in Run time. So to sum up you will have 10(in Dota but 6 is your case) scriptable object in your scene but you will only modify the images and nicknames after player selects the heroes.
Another benefit would be since they are objects you can easily animate them move up and down adjust however you want.
Here is a tutorial from Brackeys that is perfect for your case. Good luck!
I have an Unity 3D scene with several cameras looking at the same object (a huge brain mesh ~100k tri) but not necessary with the same point of view.
In the same 3D scene there is a huge number of spheric plots meshes (from 100 to 30000).
In all the cameras i have to display the brain mesh with a part of the plots meshes.
Depending on the camera view, each plot can have a different size (mesh filter and spheric collider), a different material (opaque or transparent) and can be visible or not.
The spheric collider must have the same size than the mesh.
I set up a shared mesh in common for each spheric mesh.
Their material can be one of the several shared materials i have defined.
Before rendering the scene, for each camera view in the OnPreCull function i have to define which plots are visibles and how they look.
This part can be very costly, i tried several things :
setting gameobject inactive : too costly
setting local scale to vector3(0,0,0) : better but i can see that the rendering is still done in the profiler
setting a total transparent material : same result, but the in the profiler the rendering is now transparent instead of opaque
setting a layer not in the cameras layers masks : huge script cost
I don't kwnow if i can make an efficient culling system with all theses cameras looking at the same point...
I welcome any new ideas.
First issue:
Regarding your specific question with the four dots.
Simply set the renderer.enabled = false, that's all there is to it.
Note however that as I mention in a comment, you would never try to "cull yourself" in Unity (unless I have misunderstood your description).
Second issue:
Regarding the small spheres. I suspect you have very many in the scene. You simply can't do that. In video games (the most difficult of all 3D engineering), you just do this with billboarding. It's how say "grass" is done in a scene. You can achieve this nicely with the particle system in Unity, or other techniques. An implementation is beyond the scope of this answer, but you will have to fully investigate billboarding. Simply it's a small flat image which always faces the camera in the render pass.
Issue 2B:
Note however that sphere colliders are wonderful, and you can use as many as you want. I'm sure this is obvious from base mathematical reasons. Side tip: often folks try to "write their own" thinking it will be faster. It's impossible to outwrite the 100? person-years of spatial culling scientific research in PhysX, and moreover they use the metal, the gpu, so you can't beat it.
Issue three:
Is there a chance you're using a mesh collider somewhere in the project? Never use mesh colliders, at all. (It's extremely confusing they are mentioned or used in Unity; they only have one or two very specific limited uses.)
Issue four:
I'm confused about why you are turning things on and off. I have a guess.
I suspect you are not using more than one "stage"!
There's an amazing trick about video games when you have more than one camera. In fact you have "offscreen" scenes! So you may have players in a dungeon or the like. Off "to the side" you may have an entirely duplicate or triplicate setup of the whole thing running (you could "see it if the camera turned the wrong way") for the other cameras. (In the example you would have different qualities on the dopplegangers, coloring, map-style or whatever the case is.) Sometimes you make a whole double just to run physics calculations or address other problems.
Fascinating extreme example of that sort of thing.
In short in your situation,
You likely need one whole 'stage' of a camera and brain for each of the camera views!
Again this can be http://answers.unity3d.com/answers/299823/view.html but it is indeed the everyday thing. In your overall scene you will see eight happy brains sitting in a row, each with their own camera. In each one you would display whatever items/angle etc are relevant. (Obviously, if certain items are "identical, other than the viewing angle" you could use the "same brain with more than one camera": but I would not do that, best to have one-brain-one-camera for each view.)
I believe that could be the fundamental issue you're having!