Unity – Why does changing the texture of the particle system using the material property block change the texture, while the particle system still emits an old texture?

I try the code in Start, the activation of the editor shows a new texture, but the particle system still emits the old texture. The script works for SpriteRenderer, but not ParticleSystem. I've tried to play / stop the show – no difference.

    ParticleSystemRenderer renderer = gameObject.GetComponent();
    MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();
    renderer.GetPropertyBlock(materialPropertyBlock);
    materialPropertyBlock.SetTexture("_MainTex", texture);
    renderer.SetPropertyBlock(materialPropertyBlock);

How to increase the thickness (size) of an aircraft in Unity

I'm doing a little game where you have to ride and not fall off a platform. I use an airplane to simulate the ground, but it is really thin. Is there a way to make it thicker by increasing a variable?

How to add a Facebook connection to a Unity game without Gameroom?

I'm trying to implement the connection to Facebook with the Facebook SDK for Unity. The documentation gives a fairly simple sound: call FB.Init, then FB.LogInWithReadPermissions and use a callback to handle the response. At no time does it mention additional requirements, such as specific game clients.

Everything works in the editor, but when I try to run a build, the Init call fails with the error message "The name of the pipe did not been transmitted to the application at startup.
Make sure you are using the facebook game client. "

…Yeah. That's a bit of what I'm trying to spell out do not do here; it was built to work on Steam, and I've seen other Steam games offer Facebook authentication, so I know it's possible. I just do not know how, and Facebook's documentation is no help because it does not even mention Gameroom in conjunction with these APIs!

Does anyone know what to do to put this in place? Using Unity 2019.2.2f1 and the Facebook SDK 7.17.2.

Unity ads displaying only Unity products

I just set up unit ads on my project and now it only shows one unit product each time. Can any one suggest why? Thank you..

Embedded Systems – Unity Cmock Test Problem in Keil uVision

I'm trying to get a C project in Keil uVision to use Unity / Cmock for unit testing. I managed to pass the tests and when I reach the end of the test, I get the right number of tests and success. The problem is that after the end of the test, the program continues and calls the function tested once again, which causes an error message indicating that the function has been called more times than expected.
Using the debugger, I can see that the test beam is completed successfully, but then the program comes directly into the user function being tested.

Any ideas on what the problem might be?

lighting – Unity light cooked in memory

I have a problem: every time I try to cook light in my scene, I get this error after a while:

Clustering job failed for system: 0xde0e37c3393f9955a3f751d3aff6b594, error: 4 - 'Out of memory loading input data.'.
Please close applications to free memory, optimize the scene, increase the size of the pagefile or use a system with more memory.
Total memory (physical and paged): 42560MB.

My scene is a small to medium pitch with a skybox.

What can I do to make sure I can prepare my scene?

Where can I download the header / cover template for Unity Asset Store?

Previously, the template could be uploaded to the page with the resource publishing rules. Now he's gone. Where did he go?he

exceptions – NullReferenceException in Unity

Value type vs Reference type

In many programming languages, variables have what is called a "data type". The two types of primary data are the value types (int, float, bool, char, struct, …) and the reference type (class instance). While value types contain the to promote himself, references contains a memory address pointing to a portion of the memory allocated to hold a set of values ​​(similar to C / C ++).

For example, Vector3 is a type of value (a structure containing the coordinates and some functions) while the components attached to your GameObject (including your custom scripts inheriting from MonoBehaviour) are reference types.

When can I have a NullReferenceException exception?

NullReferenceException are raised when you try to access a reference variable that does not refer to any object; therefore, it is null (the memory address points to 0).

Some common places NullReferenceException will be raised:

Handling a GameObject / Unspecified Component in the Inspector

// t is a reference to a Transform.
public Transform t ;

private void Awake()
{
     // If you do not assign something to t
     // (either from the Inspector or using GetComponent), t is null!
     t.Translate();
}

Recover a component that is not attached to GameObject and then try to manipulate it:

private void Awake ()
{
    // Here, you try to get the Collider component attached to your gameobject
    Collider collider = gameObject.GetComponent();

    // But, if you haven't any collider attached to your gameobject,
    // GetComponent won't find it and will return null, and you will get the exception.
    collider.enabled = false ;
}

Access a GameObject that does not exist:

private void Start()
{
    // Here, you try to get a gameobject in your scene
    GameObject myGameObject = GameObject.Find("AGameObjectThatDoesntExist");

    // If no object with the EXACT name "AGameObjectThatDoesntExist" exist in your scene,
    // GameObject.Find will return null, and you will get the exception.
    myGameObject.name = "NullReferenceException";
}

Note: Be careful, GameObject.Find, GameObject.FindWithTag, GameObject.FindObjectOfType only return the gameObjects that are activated in the hierarchy when the function is called.

Try to use the result of a getter that comes back null:

var fov = Camera.main.fieldOfView;
// main is null if no enabled cameras in the scene have the "MainCamera" tag.

var selection = EventSystem.current.firstSelectedGameObject;
// current is null if there's no active EventSystem in the scene.

var target = RenderTexture.active.width;
// active is null if the game is currently rendering straight to the window, not to a texture.

Access an element of an uninitialized array

private GameObject() myObjects ; // Uninitialized array

private void Start()
{
    for( int i = 0 ; i < myObjects.Length ; ++i )
        Debug.Log( myObjects(i).name ) ;
}

Less common, but boring if you do not know about C # delegates:

delegate double MathAction(double num);

// Regular method that matches signature:
static double Double(double input)
{
    return input * 2;
}

private void Awake()
{
    MathAction ma ;

    // Because you haven't "assigned" any method to the delegate,
    // you will have a NullReferenceException
    ma(1) ;

    ma = Double ;

    // Here, the delegate "contains" the Double method and
    // won't throw an exception
    ma(1) ;
}

How to repair?

If you understand the previous paragraphs, you know how to correct the error: make sure that your variable refers (pointing to) an instance of a class (or containing at least one function for them). delegates).

Easier to say than to do? Yes indeed. Here are some tips for to avoid and identify the problem.

The "dirty" way: The try & catch method:

Collider collider = gameObject.GetComponent();

try
{
    collider.enabled = false ;
}       
catch (System.NullReferenceException exception) {
    Debug.LogError("Oops, there is no collider attached", this) ;
}

The "cleaner" way (IMHO): the check

Collider collider = gameObject.GetComponent();

if(collider != null)
{
    // You can safely manipulate the collider here
    collider.enabled = false;
}    
else
{
    Debug.LogError("Oops, there is no collider attached", this) ;
}

Faced with an error that you can not solve, it's always A good idea to find the cause of the problem. If you are "lazy" (or if the problem can be solved easily), use Debug.Log display information on the console that will help you identify what might be causing the problem. A more complex method is to use the stitches and debugger of your IDE.

Using Debug.Log is very useful for determining which function is called first, for example. Especially if you have a function responsible for initializing fields. But do not forget to remove those Debug.Log not to clutter your console (and for performance reasons).

Another tip, do not hesitate to "cut off" your function calls and add Debug.Log make checks.

Instead of :

 GameObject.Find("MyObject").GetComponent().value = "foo" ;

Do this to check if all references are defined:

GameObject myObject = GameObject.Find("MyObject") ;

Debug.Log( myObject ) ;

MySuperComponent superComponent = myObject.GetComponent() ;

Debug.Log( superComponent ) ;

superComponent.value = "foo" ;

Even better :

GameObject myObject = GameObject.Find("MyObject") ;

if( myObject != null )
{
   MySuperComponent superComponent = myObject.GetComponent() ;
   if( superComponent != null )
   {
       superComponent.value = "foo" ;
   }
   else
   {
        Debug.Log("No SuperComponent found onMyObject!");
   }
}
else
{
   Debug.Log("Can't find MyObject!", this ) ;
}

sources:

  1. http://answers.unity3d.com/questions/47830/what-is-a-null-reference-exception-in-unity.html
  2. https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it/218510#218510
  3. https://support.unity3d.com/hc/en-us/articles/206369473-NullReferenceException
  4. https://unity3d.com/fr/learn/tutorials/topics/scripting/data-types

How to detect a pinch in Unity?

How to detect a pinch motion on Unity for an Android or Iphone? I also need to know if the player pinches a certain character or not. How am I doing this?

rotation – Unity: transform.LookAt (target) does not "look" at the target?

It's been several hours since I repair a prefabricated and I have more ideas. It is a method with which I thought to be comfortable, transform.LookAt (target). I have this prefab:

enter the description of the image here

As you can see, I checked that the eye registration points were in the center of the mass; I've also verified that they were spinning correctly for the X, Y and Z axes. The yellow ball you see is the target object and NOT NOW inside the prefabricated.

I've tried two ways to get the eyes to look at the target. The first is this script, which caused a 90-degree eye-stroke in the counter-clockwise direction around the y-axis (which is very false). I applied this script to both eyes. Check it out:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LookAt : MonoBehaviour
{
    public Transform target = null;

    // Update is called once per frame
    void Update()
    {
        transform.LookAt(target);            
    }
}

And please, before thinking it: Yes, I remembered to set the target object in the editor. You can see the eyes pointing to the side instead of the target:

enter the description of the image here

I found this other script on the Unity documentation that was not working at first, but then I replaced "Rotation" with "LocalRotation", since I was near, inverted the vector "RelativePos" ", and it worked – but only on the y-axis:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LookAt : MonoBehaviour
{
    public Transform target = null;

    // Update is called once per frame
    void Update()
    {
        Vector3 relativePos = transform.position - target.position;

        // the second argument, upwards, defaults to Vector3.up
        Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up;
        transform.localRotation = rotation;

    }
}

You can see here that it works in the XY plane at eye level, but take my word when I say that the eyes can not look up or down if I move the ball up and down:

enter the description of the image here

How can I solve this problem so that the eyes always look at the target I need?
Thank you sincerely for your time.