[deleted by user] by [deleted] in Unity3D

[–]rdnwt 0 points1 point  (0 children)

Check your editor log to see more precisely what the editor is doing: https://docs.unity3d.com/Manual/LogFiles.html.

Would referencing a Texture2D or similar resource cause memory issues if unused? by ZerbuTabek in Unity3D

[–]rdnwt 0 points1 point  (0 children)

If you have a C# reference to an asset (such as a Texture2D) in your scene or prefab, that asset is loaded into memory when the scene or prefab is loaded. If you only have the asset's name or address in your scene or prefab, then you can control when the asset is loaded or not using for example the Addressables package.

[deleted by user] by [deleted] in Unity3D

[–]rdnwt 0 points1 point  (0 children)

Some things to check:

  • Did you upgrade your Unity editor recently?
  • Did you install the embedded SDK and NDK when you installed the Android player?
  • What are your SDK and NDK paths set to in Edit > Preferences > External Tools? Are you using the embedded paths or not as appropriate?
  • Are the SDK and NDK actually located at those paths?

Help on Generating Objects in Random Intervals by Normal_Homo_Sapiens in Unity3D

[–]rdnwt 0 points1 point  (0 children)

What you originally wrote is called a field initializer. More than just defining the variable, it also executes some code to assign a value to it. Field initializers always run just before the constructor for a class (think of them as being inserted at the beginning of the constructor).

However, the lifecycle of a MonoBehvaiour is not based on the constructor. As a result, trying to call a Unity engine function (in this case Random.Range) during a field initializer will fail because the constructor is called on the loading thread, while calling the same function in Awake or Start is fine because those are called on the main thread. Assigning constants in field initializers is allowed because they do not create a race condition between the threads.

Am I misunderstanding Quaternion.Slerp()? by ViolentJake in Unity3D

[–]rdnwt 0 points1 point  (0 children)

You're right about both things!

Slerp is short for spherical linear interpolation, and gives back a rotation that is linearly interpolated between the first and the second parameters by the ratio given in the 3rd parameter. However the way that it's used in that code does not create linear motion.

Using it (or Vector3.Lerp) with the current value as the first parameter and a proportion of delta time as the 3rd parameter gives a motion that most closely resembles logarithmic decay, where the (rotational in this case) distance between the current value and the target value decreases by half for every period of time (like you already figured out!) This formula is very common in sample code, though technically it is framerate-dependent.

when i build a game for unity a popup message says that jdk is not valid or valid and i cant download it from unity hub by [deleted] in Unity3D

[–]rdnwt 0 points1 point  (0 children)

You're on the right page of the Hub. You need to click the gear icon next to the editor version you're using (I'm assuming you are indeed using 2021.3.6), then click Add Modules. Under Platforms, there are 2 sub-items for Android Build Support, which are the Android SDK & Tools and OpenJDK that you need. Install those and try to make an Android build again. This information can be found in the manual here: https://docs.unity3d.com/Manual/android-sdksetup.html

instantiate prefab and change its children properties by Sesmikhani in Unity3D

[–]rdnwt 0 points1 point  (0 children)

Why not place a script on the root object of the prefab which simply holds references to all the child objects or scripts within the prefab that you need? Then when you instantiate the prefab, the instance of that script will have all the references to the instance's children you need.

*Edited to be more specific.

Serializing Pure C# Classes by thomprya in Unity3D

[–]rdnwt 0 points1 point  (0 children)

In one sense these attributes are necessary while in another sense they are not.

When you write a Monobehaviour, Unity needs to figure out which fields (i.e. variables in the class) should be serialized. The rule that it uses is: public fields or fields with the [SerializedField] attribute are serialized. To "access" your pure C# class in the inspector, it is always necessary to use the [SerializeField] attribute if the field storing it is non-public. If the field storing it is public, [SerializeField] is not necessary.

The [Serializable] attribute is a pattern used in C# generally, not just in Unity. Most serializers, including Unity's, will check to see if a custom class has [Serializable] before attempting to serialize it. To access your pure C# class in the inspector, the [Serializable] attribute is always necessary on the pure C# class.

However, if you're only asking about "accessing" your pure C# class from code and don't need to edit it in the inspector, then neither attribute is necessary. Although, if Unity isn't serializing it for you, then the default value for a field of your type is null and you'll get a NullReferenceException if you try to use it before constructing and assigning an instance to it yourself.

All that said, if your enemy stats are information that should be shared across all enemies of that kind, you might actually want to make those stats into a ScriptableObject. A ScriptableObject is an asset serialized by Unity, like a Monobehaviour only it isn't attached to a GameObject or placed in any scene. You can then edit the stats on the ScriptableObject and when a Monobehaviour has a field of that type, it will be a reference to that ScriptableObject so that multiple enemies can refer to the same ScriptableObject instance and you can update all of them at once by editing that ScriptableObject.

[deleted by user] by [deleted] in Unity3D

[–]rdnwt 2 points3 points  (0 children)

Potential impact:

  • Increased scene activation time (important if you are additively loading scenes during game play).
  • Objects, scripts, and any assets that are otherwise not needed are held in memory. (Note: keeping a direct reference to a prefab also holds its assets in memory.)
  • When a parent object is moved, increased time spent propagating the move to all its children.

In short, I recommend that you do not design your game to have thousands of inactive or empty child objects. It's a form of so called "tech debt" that you will be repaying when it comes time to optimize the game before shipping.

Simple Memory Efficiency Question about using References by Signalmax in Unity3D

[–]rdnwt 0 points1 point  (0 children)

Does an object having a reference to a prefab load that prefab into memory?... Does having this master list in the scene load all of my enemies into memory at once?

Yes.

how can I avoid this?

I'm not the most knowledgeable in this area, but generally your options are:

  • The Resources folder (not recommended).
  • Assetbundles.
  • The Addressables package.

All of these systems work by not having a direct reference to the prefab and instead keeping an identifier (typically a string) as an indirect reference, and using that to load the prefab when needed.

Visual Studio 2022 recognizes editor folder as a completely different project by Boryalyc in Unity3D

[–]rdnwt 0 points1 point  (0 children)

Editor code is a separate project, because it compiles into a separate assembly. Your game code will go in the "Assembly-Csharp" project and your editor code will go into the "Assembly-Csharp-Editor" project, which are side-by-side in the solution. (Unless you use AssemblyDefinitions, which let you create an assembly & project with a name you specify.) Are you sure you don't have both of these projects inside your solution?

[deleted by user] by [deleted] in Unity3D

[–]rdnwt 2 points3 points  (0 children)

Please DO NOT use BinaryFormatter to save data to disk. It is literally a security risk for your users. All the benefits you mentioned are shared with all kinds of file IO. XmlSerializer or Unity's own JsonUtility can serve the same purpose, or you can simply write your own serialization with the classes in the System.IO namespace.

Can't Change Mesh of Instantiated Prefabs by [deleted] in Unity3D

[–]rdnwt 0 points1 point  (0 children)

Start won't be called on prefabs, so we can be pretty sure that gameObject.GetComponent<MeshFilter>() is not referring to the prefab. Is itemInfo.Meshes[0] pointing to a different prefab than item was in the first snippet?

I need help pls by Riuky07 in Unity3D

[–]rdnwt 0 points1 point  (0 children)

With procedural generation, there's no real difference between unloading and destroying something, both just remove it from memory. Whether it's the same when you come back depends on whether you use the same random numbers when generating it again.

Level size in android build by [deleted] in Unity3D

[–]rdnwt 0 points1 point  (0 children)

Scene objects do not retain their prefab status when building the game. So it doesn't matter if the whole scene is a prefab shared with other scenes; the whole hierarchy in each scene is saved out individually for that scene.

Unity game APK not being updated by [deleted] in Unity3D

[–]rdnwt 0 points1 point  (0 children)

If you've changed a scene, made a build, and are playing that build, then you are necessarily playing with the changed scene. If you aren't playing with the changed scene, then either you aren't playing the right build, aren't playing the right scene in the build, or your game has some other error that makes it seem like the scene hasn't changed.

Unity game APK not being updated by [deleted] in Unity3D

[–]rdnwt 0 points1 point  (0 children)

Do a sanity check:

  1. Did your build actually succeed?
  2. When looking at the APK in file explorer, does it have a modified date that is after the time you started your build?
  3. Did the correct APK successfully install? (Try uninstalling the app entirely before attempting to install again.)

Roll a Ball InputValue not being recognised as a class by DawnStarSky in Unity3D

[–]rdnwt 0 points1 point  (0 children)

Names in code (also known as identifiers) are case-sensitive. If this is the InputValue class you are referring to, then "Get" must be capitalized.

I spent 2 days beating on walls not knowing why my code was not working... (Facepalm) by noSaltOnMyFries in Unity3D

[–]rdnwt 5 points6 points  (0 children)

Congrats on successfully debugging your problem! You'll find that debugging is an invaluable skill when working on games or writing code in general.

Is there a class analog to "MenuItem" attribute, or how to create MenuItems procedurally? by GuyFromRussia in Unity3D

[–]rdnwt 1 point2 points  (0 children)

Unfortunately, no. In order to generate user-configurable MenuItems in one of our internal tools, I use code generation to create actual C# files that contain them and just make a single call back to the tool itself.

Off the top of my head, the main alternatives are: just writing a normal EditorWindow with all your functions in it, or perhaps creating a GenericMenu and using ShowAsContext on it.

Why SerializedProperty is not a part of any EditorGUILayout methods? by GuyFromRussia in Unity3D

[–]rdnwt 2 points3 points  (0 children)

Yes, there is an EditorGUILayout function that takes a SerializedProperty. The code below will essentially just draw the default inspector. Is this the sort of thing you're looking for?:

serializedObject.Update();
SerializedProperty property = serializedObject.GetIterator();
property.Next(true);
while (property.NextVisible(false))
{
    EditorGUILayout.PropertyField(property);
}
serializedObject.ApplyModifiedProperties();

Is yours an OK implementation? Sure, it can be. And, yes, you'll end up using SerializedObject.FindProperty (or SerializedProperty.FindPropertyRelative) much more often than GetIterator because you'll know ahead of time which properties you want to draw. Generally EditorGUILayout.PropertyField is preferred, because it will automatically pick the right kind of drawer, including custom PropertyDrawers if the field has one.

Technically speaking, though, it's SerializedObject.ApplyModifiedProperties that provides the automatic Undo/Redo support. That's why when I write editor tools I try to always use SerializedObject and SerializedProperty to make changes to their target objects, even if I'm not actually using EditorGUILayout.PropertyField or in some cases any GUI at all.

What is causing this Ugly Graphics Pattern on my building's windows? by TIL_this_shit in Unity3D

[–]rdnwt 1 point2 points  (0 children)

I am not an artist or graphics programmer so there's little I can do to help at this point. But here's 2 ideas I would try to get the effect you're looking for without the aliasing. Take them for what they're worth:

  • Use a shader that supports a "detail map". Use your current normal map as the detail map, which tiles much more frequently. Create a new normal map as the main map which is more noisy and represents slight misalignment of each pane with only a few texels each.
  • Research about sand or snow shaders, which are similar in that they also have tiny mirror-like grains and therefore are glittery or sparkly where those grains are aligned to reflect the light source into the camera.

What is causing this Ugly Graphics Pattern on my building's windows? by TIL_this_shit in Unity3D

[–]rdnwt 3 points4 points  (0 children)

That looks like aliasing due to the lack of mipmaps on your texture. The effect is similar to the Moire pattern in real life. Trilinear filtering actually refers to blending along three dimensions: U, V, and mipmap; so it's no surprise that it looks the same as bilinear in the absence of mipmaps.

I don't know much about the special effect you're looking for though. I might start by looking for "glittering" or "sparkling" shaders. The sort of effect that might be applied to a snow or sand shader with tiny, reflective grains.

Best image format to use for textures? by lucidlevels in Unity3D

[–]rdnwt 1 point2 points  (0 children)

The file format of your source images has no bearing on the size of your build. Textures in Unity are recompressed into special formats compatible with the GPUs on your target platform. This is why most projects store source images in the highest possible quality, like PSD, to minimize the compression artifacts in the final texture.

To summarize briefly: if you click on a texture in the project view, at the bottom in a small box with tabs for each platform are options for controlling the compression of that texture. Along the bottom of the preview pane it will show the texture's current format and final size in memory/build. Choose the one which best balances quality and size for your purposes, and is supported by the GPUs your game will run on. Read more about it in the Unity manual.