#StackBounty: #unity #ai Agent trying to reach same position as other agents, instead start spinning in place

Bounty: 50

I create units in my game and have a rally point where they should walk to when created, like Age of Empires.

My problem is that since they compete for this position after a while, sometimes they end up doing this:

https://gfycat.com/decentquestionableandeancondor

https://gfycat.com/densehonoredgalapagosalbatross

As you can see one of the guys cant reach the rally point, so he starts rotating.

I realize this has to do with stopping distance, but no matter how high I set the stopping distance this eventually becomes a problem when there are many enough units. And if I set it too high they dont walk to the rally point at all, since its not THAT far from the building they spawn from.

Is there any way to manage this scenario? i.e just making him go as close as he can, and then stop?

My AI Script:

using UnityEngine;
using UnityEngine.AI;

[RequireComponent(typeof(NavMeshAgent))]
public class BaseAi : MonoBehaviour
{
    [HideInInspector]
    public NavMeshAgent agent;

    [HideInInspector]
    public NavMeshObstacle obstacle;

    float sampleDistance = 50;

    Transform mTransform;

    private void Awake()
    {
        agent = GetComponent<NavMeshAgent>();
        obstacle = GetComponent<NavMeshObstacle>();
        mTransform = transform;
    }

    private void Start()
    {
        agent.avoidancePriority = Random.Range(agent.avoidancePriority - 10, agent.avoidancePriority + 10);
    }

    void LateUpdate()
    {
        if (agent.isActiveAndEnabled && agent.hasPath)
        {
            var projected = agent.velocity;
            projected.y = 0f;

            if (!Mathf.Approximately(projected.sqrMagnitude, 0f))
                mTransform.rotation = Quaternion.LookRotation(projected);
        }
    }

    /// <summary>
    /// Returns true if the position is a valid pathfinding position.
    /// </summary>
    /// <param name="position">The position to sample.</param>
    public bool SamplePosition(Vector3 point)
    {
        NavMeshHit hit;
        return NavMesh.SamplePosition(point, out hit, sampleDistance, NavMesh.AllAreas);
    }

    public bool SetDestination(Vector3 point)
    {
        if (SamplePosition(point))
        {
            agent.SetDestination(point);
            return true;
        }

        return false;
    }

    public void Teleport(Vector3 point)
    {
        agent.Warp(point);
    }

    /// <summary>
    /// Return true if agent reached its destination
    /// </summary>
    public bool ReachedDestination()
    {
        if (agent.isActiveAndEnabled && !agent.pathPending)
        {
            if (agent.remainingDistance <= agent.stoppingDistance)
            {
                if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f)
                {
                    return true;
                }
            }
        }

        return false;
    }

    public void ToggleObstacle(bool toggleOn)
    {
        agent.enabled = !toggleOn;
        obstacle.enabled = toggleOn;
    }

    void OnDrawGizmos()
    {
        if (agent == null) { return; }
        if (agent.path == null) { return; }

        Color lGUIColor = Gizmos.color;

        Gizmos.color = Color.red;
        for (int i = 1; i < agent.path.corners.Length; i++)
        {
            Gizmos.DrawLine(agent.path.corners[i - 1], agent.path.corners[i]);
        }
    }
}

enter image description here


Get this bounty!!!

#StackBounty: #unity #c# #animation How can I play an animation only using C#, without animation controller, or create an animation con…

Bounty: 50

I’ve been looking around for a while trying to figure out how to play simple animations with Unity via ONLY C# script, with no drag-and-drop involved. So far I’ve found various tutorials explaining how to manually set up a animation controller for each object, then manually select each animation state and manually create a transition then manually set the transition length to the most minimum possible etc…

I was wondering if there’s a simple way to just do something like…

gameObject.playAnimation(
    "stand still /* which would be the name of the action state created in blender or other animation software*/", 
    "loop");

…WITHOUT creating an animation controller manually at all, I haven’t been able to find any resource to do this simple thing yet.


Get this bounty!!!

#StackBounty: #unity #c# #meta How to manage game-object script component and values in new updated model in unity

Bounty: 50

I have several objects/Models/FBX that contain different childrens and it attached several mono-behavior scripts with different values assigned publicly in the inspector (settings). SO of the assignments are manually drag-and-drop in the inspector.

Now the problem is each time we update the model in the project (FBX in the project) we have to drag and drop the model/FBX again in the hirarchy. It means that we have to attach all the scripts again with the values/Data (that we assigned in the inspector) again.

I am currently looking for the right way to do this job. Currently, I place both new and old Models in the scene and then one by one I copy-paste the old object’s script component into the new objects by viewing every child of an object. Then, I delete the old one model from the hirarchy. It is a very time consuming process. I want to automate it. Just like Unity I should save all the information (Components and assignment) of a game-object in a separate file (meta file custom) and bring them again on button click. But its challenging as i dont know how to save assignments (refrence objects).

Note: I have to bring the fbx again in hierarchy because sometimes the object not properly update in the scene. Like mesh gets rotate or scaled in weird manner. Or sometime FBX childs are removed or add.


Get this bounty!!!

#StackBounty: #unity #c# #camera What causes this z position change?

Bounty: 50

This is a follow-up on the following thread.

I’m applying a code that will move an object just outside the camera’s frustum.
I have used the same code in other projects, and it worked fine.

However, I’m using it with URP now, and I’m experiencing a z-position change while I expected only a x position change.

And I just don’t see why it does that.

I have recorded a video here.

If I press the button, the cube should be moved to the left only. But it also moves to the back (z position).

And this is the script that I have applied to the cube in the video:

using System;
using UnityEngine;

public class PlaceOutsideCamera : MonoBehaviour
{
     public void PlaceOutsideFrustum(Transform uTransform, bool uLeft)
    {
        uTransform.position = pPlaceOutsideFrustum(uTransform, uLeft);
    }
    public static Vector3 pPlaceOutsideFrustum(Transform uTransform, bool uLeft)
    {
        var frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
        Ray ray;
        Plane plane;

        if (uLeft)
        {
            // 1.
            ray = Camera.main.ScreenPointToRay(new Vector3(0, Camera.main.pixelHeight / 2f, 0));
            plane = frustumPlanes[0];
        }
        else
        {
            ray = Camera.main.ScreenPointToRay(new Vector3(Camera.main.pixelWidth - 1, Camera.main.pixelHeight / 2f, 0));
            plane = frustumPlanes[1];
        }

        float fDistance = Mathf.Abs(Camera.main.transform.position.z - uTransform.position.z);

        // 2.
        var borderPoint = ray.GetPoint(fDistance);

        // 3.
        var frustumOutside = -plane.normal;

        Bounds b = BoundsFromTransform(uTransform);
        // 4.
        var halfDiameter = b.size.magnitude / 2f;

        return borderPoint + frustumOutside * halfDiameter;
    }
    public static Bounds BoundsFromTransform(Transform uTransform)
    {
        try
        {
            Bounds bounds = new Bounds(uTransform.position, Vector3.zero);//wir hätten auch einfach new Bounds() nehmen können, meint Manfredas

            foreach (Renderer renderer in uTransform.GetComponentsInChildren<Renderer>())
            {
                bounds.Encapsulate(renderer.bounds);
            }

            Vector3 nOff = bounds.center - uTransform.position;

            return new Bounds(nOff, bounds.size);
        }
        catch (Exception ex)
        {
            UnityEngine.Debug.Break();
            return new Bounds();
        }
    }
    public void OnGUI()
    {
        if (GUI.Button(new Rect(0, 350, 100, 50), "DoThis!"))
        {
            pDoThis();
        }
    }
    private void pDoThis()
    {
        this.PlaceOutsideFrustum(this.transform, true);
    }

}

Can anybody tell me why my code does this? I just don’t see it.
Thank you very much for the help!


Get this bounty!!!

#StackBounty: #unity #gnome #launcher #compiz Unity profile without window decorations or launchpad

Bounty: 50

From one day to another (probably after an automatic update), when I log in to my profile, I do not see window decoration or the start menu. If I use another user, everything works fine. I had this problem before, so I know it is unity and compiz related. Back then, I solved it by moving away the compizconfig directory, but this does not do the trick this time, although it seems to be a profile-related issue.

The error message reads:

Sorry, Ubuntu 16.04 has experienced an internal error.

If you notice further problems, try restarting the computer.

ExecutablePath /usr/lib/x86_64-linux-gnu/unity/compiz-config-profile-setter

Package unity 7.4.5+16.04.20190312-0ubuntu1

ProblemType: Crash

Title: compiz-config-profile-setter crashed with SIGSEGV in cssObjectGetInterface_()

.tmp.unity_support_test.0

ApportVersion: 2.20.1-ubuntu2.21

CompizPlugins: No value set for ‘/apps/compiz-1/general/screen0/options/active_plugins’

[…]

This error message appears only sometimes, the launchpad is never around though.

How do I fix my broken profile with minimal effort?

References


Get this bounty!!!

#StackBounty: #unity #c# #modding #assetbundle How to build only specified assets into assetbundle in unity

Bounty: 50

I have searched through the few results pertaining to this particular question, but haven’t found any results that work. A simple rundown of what i am looking for is to be able to make a single asset bundle of specified assets in order to be able to make an automated process for what the mod system i am making for the project i am working on.

there are two ways I can think of that would be able to do this;

  1. build specified resources and assets into an assetbundle
  2. build everything in a specified folder into an asset bundle

all of what i have been able to find regarding this either wouldn’t allow me to make the automated process i need or builds the all of the assetbundles and they have to be defined manually before hand.

Any resources or suggestions to this issue would be greatly appreciated.


Get this bounty!!!

#StackBounty: #unity #animation #blender #fbx Imported FBX animations (exported from Blender) have different, messier keyframes than in…

Bounty: 50

I imported an a character to Unity 2019.2.8 that I made in Blender 8.0, which was exported from that program in .FBX format. The animations play back the same (perceptually, but the keyframes are very messy and out of place by comparison.

What can be causing this? The animations in Blender and Unity are the same length (I checked) so what happened to the keys? How can I re-import these animations so that the keys match?

EXAMPLE:
(this all happens in Blender 8.1)

In Blender, have a rigged and animated character ready:

enter image description here

These animations (this animation in particular, “Battle_Punch”) was recorded with the Frame Rate set to 60fps. That may not be true for all of them (hope not) but it is for this one.

Prior to export, I select all the objects in under the Luigi collection. I do that by right-clicking the Armature object in the Collections panel and selecting “Select Hierarchy”.

Then I use the following FBX export settings:

enter image description here

Of particular note should be the options to export only what is selected.
I set the normals to “face” because once-upon-a-time, that worked well for me when the default did not.

Here are my FBX IMPORT settings inside Unity:

Model:

enter image description here

Rig:

enter image description here

Animation (only change is Import Constraints-YES and Anim. Compression-NONE):

enter image description here

(I’m sure the Materials settings are unimportant for this)

Here are they keyframes I get with Anim. Compression set to NONE:

enter image description here

…and here is what I get with the default setting (Reduced Keyframes). This result is the same as if I select OPTIMAL:

enter image description here

You can compare this to the keyframes in the first image and see that this outcome resembles shotgun fire better than it resembles my keyframes.

Now, an observation: Tinkering with the translation/rotation/scale error settings under Reduced Keyframes in the Animations import settings will give me more keyframes, but I can’t confirm this is more consistent with what I started with because it will insert a keyframe for every position, not just where the original keyframes were.

How do I get keyframes ONLY where my original keyframes were?


Get this bounty!!!

#StackBounty: #unity #ios #assetbundle #streaming-assets Can I persist AssetBundles if they were delivered from Apple's on-demand r…

Bounty: 50

My Unity iOS game is fairly large. It could easily be 1.5gb when installed.

To reduce download size, I’m reading about AssetBundles and Apple’s on-demand resources. It seems ideal – I could put most of my assets in Apple’s servers, dramatically reducing the download/install size, and then just download everything when the game runs for the first time (my goal is to have the players install the game as quick as possible).

However, upon further reading I’m starting to suspect that Apple’s on-demand resources are strictly meant for temporary usage. I can’t just “download the whole game and leave it like that”.

Other websites seem to further support that idea:

Data beyond the 200 MB limit will be cached for an indeterminate
period of time, then deleted automatically by the system.

(That’s for Apple TV apps but I suppose it is the same case)

Is it correct that I cannot persist my AssetBundles if they were delivered from Apple’s on-demand resources service?

Naturally I could take the assets I want from the AssetBundle and somehow write them to disk manually, and then release the AssetBundle. It can be done, but if I could simply mark the bundle as “do not delete” it would be a lot more convenient.


Get this bounty!!!

#StackBounty: #unity #ios #assetbundle #streaming-assets Can I persist AssetBundles if they were delivered from Apple's on-demand r…

Bounty: 50

My Unity iOS game is fairly large. It could easily be 1.5gb when installed.

To reduce download size, I’m reading about AssetBundles and Apple’s on-demand resources. It seems ideal – I could put most of my assets in Apple’s servers, dramatically reducing the download/install size, and then just download everything when the game runs for the first time (my goal is to have the players install the game as quick as possible).

However, upon further reading I’m starting to suspect that Apple’s on-demand resources are strictly meant for temporary usage. I can’t just “download the whole game and leave it like that”.

Other websites seem to further support that idea:

Data beyond the 200 MB limit will be cached for an indeterminate
period of time, then deleted automatically by the system.

(That’s for Apple TV apps but I suppose it is the same case)

Is it correct that I cannot persist my AssetBundles if they were delivered from Apple’s on-demand resources service?

Naturally I could take the assets I want from the AssetBundle and somehow write them to disk manually, and then release the AssetBundle. It can be done, but if I could simply mark the bundle as “do not delete” it would be a lot more convenient.


Get this bounty!!!

#StackBounty: #unity #ios #assetbundle #streaming-assets Can I persist AssetBundles if they were delivered from Apple's on-demand r…

Bounty: 50

My Unity iOS game is fairly large. It could easily be 1.5gb when installed.

To reduce download size, I’m reading about AssetBundles and Apple’s on-demand resources. It seems ideal – I could put most of my assets in Apple’s servers, dramatically reducing the download/install size, and then just download everything when the game runs for the first time (my goal is to have the players install the game as quick as possible).

However, upon further reading I’m starting to suspect that Apple’s on-demand resources are strictly meant for temporary usage. I can’t just “download the whole game and leave it like that”.

Other websites seem to further support that idea:

Data beyond the 200 MB limit will be cached for an indeterminate
period of time, then deleted automatically by the system.

(That’s for Apple TV apps but I suppose it is the same case)

Is it correct that I cannot persist my AssetBundles if they were delivered from Apple’s on-demand resources service?

Naturally I could take the assets I want from the AssetBundle and somehow write them to disk manually, and then release the AssetBundle. It can be done, but if I could simply mark the bundle as “do not delete” it would be a lot more convenient.


Get this bounty!!!