FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • Inconsistent android build sizeCheckerT
    I have build a simple 2D game with unity. When build for android, the build size is around 32 MB. However when I install and run the app, we're looking about double the size. (App - 60.22 MB, Data - 106 KB, Cache - 172 KB, Total - 60.49 MB) I am using Samsung Galaxy A 40, but the same symptom keeps showing on other devices. Where does the extra 30 MB come from? Why does unity create 106 KB data for seemingly no reason (I know this isn't much, but I can't find where those files are located)
     

Inconsistent android build size

I have build a simple 2D game with unity. When build for android, the build size is around 32 MB.

Build size

However when I install and run the app, we're looking about double the size.

App size

(App - 60.22 MB, Data - 106 KB, Cache - 172 KB, Total - 60.49 MB)

I am using Samsung Galaxy A 40, but the same symptom keeps showing on other devices.

Where does the extra 30 MB come from? Why does unity create 106 KB data for seemingly no reason (I know this isn't much, but I can't find where those files are located)

  • ✇Recent Questions - Game Development Stack Exchange
  • Rigidbody Simulated vs Static vs noneCheckerT
    I am confused about the usage of static / not simulated rigidbodies. I get that it is better to disable simulated to temporarily stop a rigidbody rather than deleting and recreating it, especially because all references wont get destroyed, but why are there two options to stop it? What is the difference between a static rigidbody and a not simulated rigidbody? Also I have heard that peoplre create a lot of colliders with static/not simulated colliders. Why bother to create rigidbodies at all if
     

Rigidbody Simulated vs Static vs none

I am confused about the usage of static / not simulated rigidbodies.

I get that it is better to disable simulated to temporarily stop a rigidbody rather than deleting and recreating it, especially because all references wont get destroyed, but why are there two options to stop it? What is the difference between a static rigidbody and a not simulated rigidbody?

Also I have heard that peoplre create a lot of colliders with static/not simulated colliders. Why bother to create rigidbodies at all if the gameObject is never meant to move? Doesn't this just waste processing power to a thing that is completely unnecessary?

  • ✇Recent Questions - Game Development Stack Exchange
  • Deleting components via OnValidate script while in editorCheckerT
    I want to create different types of platforms for my game, and they are currently all in different prefabs. This works fine, but it is just taking so long to search for the prefab, dragging it in, and maybe if I dragged the wrong one into the scene, I would need to create a new platform from scratch. My idea is that you have a custom inspector for a script that sits on an example platform, and have an enum to choose what kind of platform is placed. This idea worked until I tried to delete / add
     

Deleting components via OnValidate script while in editor

I want to create different types of platforms for my game, and they are currently all in different prefabs. This works fine, but it is just taking so long to search for the prefab, dragging it in, and maybe if I dragged the wrong one into the scene, I would need to create a new platform from scratch.

My idea is that you have a custom inspector for a script that sits on an example platform, and have an enum to choose what kind of platform is placed. This idea worked until I tried to delete / add components that are not needed for the platform (A spike platform does not need a script to destroy it when clicked, while a destructable platform does not need a spike script). Right now I don't need the custom inspector, but I will add it in the future.

When I try to run this script:

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

public class PlatformTypeChanger : MonoBehaviour
{
    enum PlatformType { Default, Destruckt, Spike, HingeJoint};
    [SerializeField] PlatformType platformType;

    private void OnValidate()
    {
        switch (platformType)
        {
            case PlatformType.Default:
                Default(); break;
            case PlatformType.Destruckt:
                Destruct(); break;
        }
    }

    void Default()
    {
        Destroy(GetComponent<Spike>());
    }

    void Destruct()
    {
        if (!GetComponent<Spike>())
        {
            gameObject.AddComponent<Spike>();
        }
    }
}

I get error:

Destroy may not be called from edit mode! Use DestroyImmediate instead.
Destroying an object in edit mode destroys it permanently.
UnityEngine.Object:Destroy (UnityEngine.Object)
PlatformTypeChanger:Default () (at Assets/PlatformTypeChanger.cs:23)
PlatformTypeChanger:OnValidate () (at Assets/PlatformTypeChanger.cs:15)

Destroy may not be called from edit mode! Use DestroyImmediate instead.
Destroying an object in edit mode destroys it permanently.
UnityEngine.Object:Destroy (UnityEngine.Object)
PlatformTypeChanger:Default () (at Assets/PlatformTypeChanger.cs:23)
PlatformTypeChanger:OnValidate () (at Assets/PlatformTypeChanger.cs:15)

Destroy may not be called from edit mode! Use DestroyImmediate instead.
Destroying an object in edit mode destroys it permanently.
UnityEngine.Object:Destroy (UnityEngine.Object)
PlatformTypeChanger:Default () (at Assets/PlatformTypeChanger.cs:23)
PlatformTypeChanger:OnValidate () (at Assets/PlatformTypeChanger.cs:15)

[Worker1] Destroy may not be called from edit mode! Use DestroyImmediate instead.
Destroying an object in edit mode destroys it permanently.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

If I Change Destroy() to DestroyImmediate() I get this error:

Destroying components immediately is not permitted during physics trigger/contact, animation event callbacks, rendering callbacks or OnValidate. You must use Destroy instead.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
PlatformTypeChanger:Default () (at Assets/PlatformTypeChanger.cs:23)
PlatformTypeChanger:OnValidate () (at Assets/PlatformTypeChanger.cs:15)

So I should neither use Destroy() nor DestroyImediate() ? What other methods are there?

  • ✇Recent Questions - Game Development Stack Exchange
  • 2D Physics inconsistent across platformsCheckerT
    I want to create a black hole like gravity pull effect in Unity2D, and used that code for this: using UnityEngine; public class Attractor : MonoBehaviour { public Transform player; private Rigidbody2D playerBody; public float influenceRange; public float intensity; void Start() { playerBody = player.GetComponent<Rigidbody2D>(); } void Update() { float distanceToPlayer = Vector2.Distance(player.position, transform.position);
     

2D Physics inconsistent across platforms

I want to create a black hole like gravity pull effect in Unity2D, and used that code for this:

using UnityEngine;

public class Attractor : MonoBehaviour
{
    public Transform player;
    private Rigidbody2D playerBody;
    public float influenceRange;
    public float intensity;

    void Start()
    {
        playerBody = player.GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        float distanceToPlayer = Vector2.Distance(player.position, transform.position);
        
        if (distanceToPlayer <= influenceRange)
        {
            Vector2 pullForce = (player.position - transform.position).normalized * intensity;
            playerBody.AddForce(pullForce, ForceMode2D.Force);
        }
    }
}

Intensity is set to 5 and influenceRange to 4.

All references are set up correctly.

In the Unity Editor the pull effect seems much stronger than on android though.

Pull Effect on android:

Pull effect on android

I can't show pull effect in the editor because I'm not home now, but there the ball flies through the sky and gets attracted much stronger.

Any help is appreciated!

❌
❌