#archived-code-general

1 messages · Page 422 of 1

woeful hamlet
#

I see.

#

Did I get this right?

rigid island
#

yes the collectable just Calls the method Score, then that method does its own Invoke of the event, the event lives on score script because it makes sense for a score tracker to have an alert to when score update. You should not make the method static though otherwise you cannot reference anything else within that class without it also be static which can be a mess

#

also static fields don't show up in unity so you cannot even link anything like reference through it

#

this makes the one spawned Instance(object) of that class static, makes it easy to access its methods / properties without having to make everything else static

woeful hamlet
#

Does this look about right? I didn't have anything else yet that could listen to the event, so I couldn't quickly test it.

rigid island
#

in that case no point Score being static

#

notice how you could only access score through instance in its static method

#

so yeah if you have singleton, everything else does not need to be static, just public if you want acces to them elsewhere. like method

woeful hamlet
#

THis is what happens when I try to make Score non-static. The game actually keeps running, but the line in the cups that should destroy them doesn't fire either.

vast finch
#

I have encountered weird problem with loaded data.

My data is stored with the help of a binary formatter, with every generated league, team, player and manager kept as a list of lists, with entries storing all the data i need. Code seems to work just fine, however - the following issue has appeared!

After loading data, my game starts progressing through the days much slower, both in editor and after i build and run it. I can't figure out what the issue is, can someone please give me at least a direction of where to look? I suspected the problem may have been in save file not being closed, but i think it should be getting closed just fine in first screenshot.

Second screenshot shows typical example of me loading data to re-create an object that was saved.

rigid island
#

normally its serialized in the inspector so it doesnt need null checking

#

If you dont want to use inspector at all just use an Action

woeful hamlet
#

What's private? the Score method is public.

#

And in the collectible I add it via collected.AddListener(ScoreScript.instance.Score);

rigid island
rigid island
woeful hamlet
#

wait nvm

woeful hamlet
#

Yeah, I got mixed up.

rigid island
#

the null is thrown because if your event has no listeners its null

woeful hamlet
#
{
    ScoreScript.instance.Score();
    Destroy(this.gameObject);
}```
rigid island
#

otherwise you need myEvent?.Invoke()

woeful hamlet
#

Now it's working perfectly.

rigid island
#

Unity event only supports unity objects and int,float, string

#

or I think thats just for the inspector ? idk I just use Action tbh

woeful hamlet
#

I see. I'm probably gonna look into those too, then.

woeful hamlet
rigid island
#

np UnityChanSalute

woeful hamlet
#

Semi-related to this, is there any reason not to put all my static logic/manager classes (like that ScoreScript, the Audio Manager, and later maybe a Health Manager) onto the same empty GameObject? Or should each one of those get its own? (Provided they're supposed to do nothing more than hold the scripts)

rigid island
#

personally find it easier sometimes on their own object cause I usuaully have other components that work with those managers that might not necessarily care about others

#

there are also very small performance implications.. even empty gameobject need to allocate resource to exist, so now you have extra allocation ontop of the script itself in small quanitities is probably non-issue but I guess with scale it can get ugly

woeful hamlet
#

I see. For the small practice stuff I'm doing rn, I'll probably leave them in one, but I guess when I do something bigger I should subdivide them a bit.

sudden ruin
#

im learning the dijkstra to traverse all possible position, finding furthest position and reachable positions at the same time, however all the guides i've seen only have use the algo for finding the shortest path between 2 pre designated points, anyone know a similiar implementation? or the steps to achieve this

cosmic rain
#

If there are extra conditions, you can just traverse all the positions in order.

sudden ruin
#

but this man doesnt show his implementation

sly shoal
#

running into an issue when running a build of my game.
the player has a collider attached to the main game object and another collider in a child object for the player

i have a script that finds the player and gets their collider.
in the unity editor, this works fine and the script successfully finds the collider on the player object
in the build of the game...the script finds the other collider on the child object.

you can see in the logs, two different object names are output. Bud is output in the editor (the correct game object), Combat is output in the build
whats with the discrepancy here?
please ignore how messy the code snippet is hehe

sudden ruin
cosmic rain
cosmic rain
cosmic rain
#

Log the found object and see what it finds in the build

sly shoal
#

you could be right about the tag thing

cosmic rain
#

Then Combat had a player tag as well

sly shoal
#

its just weird that it always finds the right object when running the game in the unity editor but when running the build, it always finds the wrong object

cosmic rain
#

Honestly, I'd avoid finding by tag at all

cosmic rain
#

That's what it means that it doesn't guarantee order.

sly shoal
sly shoal
torn vale
#

Hey how you guys doing just wanted to ask as a hipotetic question

You guys know valkyria cronicles 4? How much time would it take a expert proegrammer to make a simmilar sistem like that?

I mean it goes by turns, when its your turn its gree movement, etc. Just asking if you guys can help me with that

lean sail
dense estuary
#

I had a coroutine with while(true) { yield return new WaitForSecondsRealtime(0.05f); text.text = "FPS: " + fps + " " + ms + "ms (avg " + fpsAvg + " " + msAvg + "ms)"; } and when I got rid of the yield it caused my unity to crash. Is that expected?

#

I don't mess around with coroutines much, but I guess it would cause an infinite loop without the delay.

#

Sorry, this question was meaningless

hexed bough
#

I need a suggestion.
I want to make multiplayer black jack game
Which multiplayer framework should i use? Photon or colyseus or something else?

Its a webgl game
And i want to cover up afk players or players in background
So i dont actually want to give authority to a single player like host

quick token
craggy veldt
#

no need to wrap that string manipulation in a while loop

rigid island
#

I think the point was to refresh the variables, basically avoiding just using the Update loop

#

would've been less allocative to at least cache that if time didn't change

var waitTime = new WaitForSecondsRealtime(0.05f);
while(true) {
    yield return waitTime
    text.text = "FPS: " + fps + " " + ms + "ms (avg " + fpsAvg + " " + msAvg + "ms)";
}```
craggy veldt
rigid island
#

they removed the yield and that breaks inside while in ienumerator

craggy veldt
#

oh no now Im wrong again damn

#

so my original ain't wrong 😂

rigid island
#

yeh while loops in ienumerator always need to at least wait a frame with yield return null

#

or the frame basically never ends lol

craggy veldt
#

yeah it will block the mainthread

thin aurora
#

Just measure the time passed using Time.deltaTime and check the invokation count of Update when the time surpasses 1 second (with some additional checks to ensure you truly get the average per second but you get the idea)

maiden fractal
# sudden ruin i think this is floodfilling? not dijkstra?

If the world is based on grid, some sort of floodfill/BFS might work. However if you have stored the dungeon as a graph (positions of rooms and connecting edges between the rooms), you definitely need some sort of pathfinding algo. This article seems to present the variation of Dijkstras you are looking for https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/ (didn't read it too thoroughly to confirm it's any good)

blazing tiger
#

Are you not supposed to be using Resources.Load anymore to load content from folders?

#

I'd like to grab some textures from a directory during game startup, any alternative ways? I've seen addressables but they seem to solve a somewhat different problem

blazing tiger
#

Stuff like this

#

And I've heard it a bunch of time around here

#

And nobody ever explained why. Just "don't use it"

leaden solstice
#

Sure using Addressable lets you do more things but you can use Resources if you don’t care much about asset management

blazing tiger
#

In the thread they kinda reffer to the "best practices" but it didn't make a lot of sense to me

#

From some of the games I've dissected I've seen some outright use C# methods to access files

leaden solstice
leaden solstice
#

But you don’t get Unity-imported asset that way

vestal arch
blazing tiger
#

I'm assuming it's acceptable when you need to load content that may be modified

#

Like modding or whatever

leaden solstice
#

Neither Resources nor Addressable does not read from actual file system folder if that’s what you’re thinking of

blazing tiger
leaden solstice
#

If you were thinking you can swap out png or something on built directory then no it won’t work that way

blazing tiger
lean sail
sudden ruin
vestal arch
leaden solstice
vestal arch
#

mistakes are inevitable, it's better to catch them early (static checking and compiler errors are better than runtime errors, and that's better than silent bugs)

blazing tiger
leaden solstice
#

You can do it manually

vast ember
#

The following code is responsible for making the player not double jump, and only jump on flatter-like surfaces. It worked perfect with the 3D capsule in unity, but now when I imported a character model with capsule collider, this code doesnt work in preventing double jumps at surfaces which are not flat (elevated)

{
    CapsuleCollider capsule = GetComponentInChildren<CapsuleCollider>();

    Vector3 boxCenter = capsule.bounds.center;
    Vector3 boxHalfExtents = new Vector3(capsule.radius, groundCheckLengthOffset / 2, capsule.radius);
    Quaternion orientation = Quaternion.identity;
    Vector3 direction = Vector3.down;
    float maxDistance = capsule.bounds.extents.y + groundCheckLengthOffset;
    Debug.Log("Capsule Center: " + capsule.bounds.center);
    RaycastHit hit;

    bool isGrounded = Physics.BoxCast(boxCenter, boxHalfExtents, direction, out hit, orientation, maxDistance, groundLayerMask);

    if (isGrounded)
    {
        // Check the surface normal
        float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);

        // Allow jumping only if slope angle is within limit
        if (slopeAngle <= 45)
        {
            return true;
        }

    }

    return false;
}```
blazing tiger
#

Sure, it's just pixels. Would probably be able to just construct a bunch of textures and store them in some static registry

vast ember
#

i did a raycast before, then changed it to boxcast for an accurate raycasting

lean sail
#

Your model should have absolutely no effect on the logic happening here. The capsule collider you have is likely just the same one as the 3d capsule, unless you see it as like a mesh collider or whatever the name was

vast ember
#

just a capsule collider

lean sail
#

You should start debugging then and see at which point the logic is different in your code

leaden solstice
#

Are you getting different capsule collider with it

vast ember
#

nothing else

leaden solstice
#

Or is the boxcast blocked by something within model

vast ember
lean sail
#

A lot of the code you have is purely just defining variables. It should be pretty quick to just start debugging and seeing at which point exactly the code does something different.

lean sail
#

That boxHalfExtents thing looks unnecessary to me though, not sure why you have your own groundCheckLengthOffset in there

leaden solstice
vast ember
vast ember
#

i guess i will debug more

vast ember
lean sail
#

Tbh you could even just change this to capsule cast and use the actual capsule to determine the parameters. Boxcast might run into weird edge cases

vast ember
#

I just know that spherecast/boxcast is better than simple raycast, but which to use?

lean sail
#

Your character is a capsule, so why use a box?

vast ember
#

I just thought box l would fit it better

#

like its a humanoid

#

with arms and legs

lean sail
# vast ember its a fbx model

That's not what I was referring to. It's already made using a capsule collider. A capsule collider will cover the best area for your humanoid

vast ember
lean sail
#

The corners of a box are further out than the edge of a capsule. Your player wont be able to move in a lot more scenarios, and rotation will be weird

lean sail
vast ember
wheat cargo
#

So, I'm struggling to understand why I am seeing jitter, I am moving a rigidbody (interpolation on) with forces in FixedUpdate and having the camera follow with Vector3.SmoothDamp in LateUpdate.

public class TestPhysics : MonoBehaviour
{
    [SerializeField]
    private float speed;

    private Rigidbody rb;

    private void Awake()
    {
        rb = GetComponent<Rigidbody>();
    }

    private void FixedUpdate()
    {
        rb.AddForce(Vector3.forward * speed * Time.deltaTime);
    }
}
public class TestCameraController : MonoBehaviour
{
    [SerializeField]
    private Transform _targetTransform;

    [SerializeField]
    private Vector3 _offset;

    [SerializeField]
    private float _damping;

    private Vector3 _currentVelocity;

    void LateUpdate()
    {
        Vector3 targetPos = _targetTransform.position + _offset;

        transform.position = Vector3.SmoothDamp(transform.position, targetPos, ref _currentVelocity, _damping);
        transform.LookAt(_targetTransform);
    }
}
mellow sigil
#

SmoothDamp doesn't work when the target position moves

#

The easy solution is to use Cinemachine. Otherwise you'll have to come up with manual calculations to get the camera movement you like

wheat cargo
#

I have the same problem with Cinemachine

vestal arch
#

im using it just fine

mellow sigil
#

The issue with Cinemachine is easier to fix than this

vestal arch
mellow sigil
#

Also don't multiply forces by deltatime (unrelated to this issue)

wheat cargo
wheat cargo
#

Cinemachine has same problem

leaden solstice
wheat cargo
mellow sigil
wheat cargo
deep stirrup
#

Does someone know what can trigger this artefact in motion blur? It appears when you turn the camera a bit fast on only left and right edges of the screen. I am using unity 6 36f1 and latest urp version, here's my motion blur configuration

cosmic rain
wheat cargo
cosmic rain
#

Use the profiler to troubleshoot performance.
I think it's a combo of damping and performance

wheat cargo
vestal arch
wheat cargo
cosmic rain
wheat cargo
cosmic rain
#

I'd confirm that it's an editor issue first. And if it is, test in a build

cosmic rain
#

That's why you usually have target framerate and vsync

#

Though, it's still just a guess. You should confirm it first.

wheat cargo
cosmic rain
wheat cargo
#

since camera will only get moved at 50 fps?

cosmic rain
wheat cargo
#

but camera movements will be at 50 fps

cosmic rain
#

In normal situation it would cause slight jittering

#

but it's probably gonna be better than unstable framerate

#

Anyways, it's all speculations untill your confirm the assumption

wheat cargo
#

Yeah I'm making an FPS counter now and will make a build shortly

light wraith
#

is it possible to set unity to open new files in visual studio from the Assets folder, instead of solution view?

#

available views button shows the entire project folder instead of just assets:

maiden fractal
#

If you don't have thousands and thousands of vertices and edges, the performance wouoldn't be an issue regardless

sudden ruin
#

sorry im still a little confused of the "edges' length" here, so the line between 2 nodes is a edge and the path between 2 rooms is this edge? or is it the cost to walk 1 step on the path is the edge length. im thinking its the latter?

#

i think it would only make sense if it the latter

light wraith
maiden fractal
#

How are you representing the dungeon in your code?

sudden ruin
#

its tilemap, corridor first , generate the path by bunch of tiles in a straight lines, choose the end of the path as a potential room, so a room can be here or not, if not then path to next room is double or triple if failed again

maiden fractal
# sudden ruin this

Do you actually need this type of heatmap where every tilemap tile has their own distance or do you only need one distance per every room?

sudden ruin
#

i believe it would be more confusing if continue lol

vast ember
#

Hi, I am doing a capsule cast but somehow it isnt working. The isGrounded bool is always coming as false. Can anyone help me find whats wrong here?

 Vector3 point1 = transform.position + capsule.center - new Vector3(0f, halfCylinderHeight, 0f);
 Vector3 point2 = transform.position + capsule.center + new Vector3(0f, halfCylinderHeight, 0f);

  
 isGrounded = Physics.CapsuleCast(point1, point2, capsule.radius, Vector3.down, out hit, 1f);```
wheat cargo
# cosmic rain Anyways, it's all speculations untill your confirm the assumption

So, it does seem to be an issue of inconsistent frame timings. In a build, if I set the target framerate to 80 there is no jitter, but if I uncap it then there is jitter although slightly less noticeable at higher framerates.

My brain is just struggling to understand this, because I thought that is the whole point of Time.deltaTime is to be framerate independent. I guess it does not apply to inconsistent framerates though?

cosmic rain
cosmic rain
wheat cargo
maiden fractal
# sudden ruin you know what i think i got it, it is latter

I mean it could be either, there's multiple ways to implement it. I thought you had the data in a graph data structure where each room was a node and connections between rooms were edges (like in the earlier drawings you originally showed) in which case the former would be what you need. If you want to do the search on the tilemap or similar 2d grid, BFS/floodfill should work

sudden ruin
#

yes i didnt store what room is connect and the length between two when i gen, i could do that actually but i think dont need to

cosmic rain
true quiver
#

I need help with my vr game, i get a build error.
UnityEditor.BuildPlayerWindow+BuildMethodException: Error building Player because scripts have compile errors in the editor
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002da] in <57a8ad0d1492436d8cfee9ba8e6618f8>:0
at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <57a8ad0d1492436d8cfee9ba8e6618f8>:0
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

wheat cargo
simple egret
#

Check if there are other console errors aside this one

maiden fractal
sudden ruin
#

ok no worry i believe i will understand what i'll write in the script

rustic arch
#

Anyone has any idea why the GPU fans go crazy even in the main menu? The scene is not even that big compared to other maps

green bison
#

'''cs

#

oops]

heady iris
#

seems a bit odd

#

Note that the game will run as fast as possible if not given a framerate limit

green bison
#

'''cs
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f; // Speed at which the player moves
public float jumpForce = 7f; // Force applied when jumping
private Rigidbody2D rb; // Reference to the Rigidbody2D component
private bool isGrounded = false; // Check if the player is on the ground
public Transform groundCheck; // Ground check transform (position under the player)
public LayerMask groundLayer; // LayerMask to define what is considered ground

private void Start()
{
    rb = GetComponent<Rigidbody2D>(); // Get Rigidbody2D component
}

private void Update()
{
    // Handle Movement (Horizontal input, left/right movement)
    float moveInput = Input.GetAxis("Horizontal");
    rb.linearVelocity = new Vector2(moveInput * moveSpeed, rb.linearVelocity.y);

    // Handle Jumping
    if (Input.GetButtonDown("Jump") && isGrounded)
    {
        rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce); // Apply jump force
    }

    // Check if grounded using groundCheck position and a small radius
    isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.1f, groundLayer);
}

} '''

heady iris
#

You need to use three backticks

#

it's the lowercase tilde

#

```cs
like this
```

#

(i used backslashes to prevent the code block from being recognized)

rustic arch
green bison
#

i dont understand

heady iris
#

I just slap a 120 fps limit on when the game boots up

green bison
#
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float moveSpeed = 5f;        // Speed at which the player moves
    public float jumpForce = 7f;        // Force applied when jumping
    private Rigidbody2D rb;             // Reference to the Rigidbody2D component
    private bool isGrounded = false;    // Check if the player is on the ground
    public Transform groundCheck;       // Ground check transform (position under the player)
    public LayerMask groundLayer;       // LayerMask to define what is considered ground

    private void Start()
    {
        rb = GetComponent<Rigidbody2D>(); // Get Rigidbody2D component
    }

    private void Update()
    {
        // Handle Movement (Horizontal input, left/right movement)
        float moveInput = Input.GetAxis("Horizontal");
        rb.linearVelocity = new Vector2(moveInput * moveSpeed, rb.linearVelocity.y);

        // Handle Jumping
        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce); // Apply jump force
        }

        // Check if grounded using groundCheck position and a small radius
        isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.1f, groundLayer);
    }
}


#

there we go

naive swallow
green bison
#

theres the player script

naive swallow
#

That's the one having the issue, right?

green bison
#
using System.Collections.Generic;
using UnityEngine;

public class ShadowController : MonoBehaviour
{
    public Transform player;         // Reference to the player’s transform
    public float delay = 0.5f;       // How delayed the shadow is

    private Queue<Vector3> playerPositions;    // Queue to store player’s positions
private bool isGrounded = false;    // Check if the player is on the ground
     public Transform shadowgroundCheck;       // Ground check transform (position under the player)
    public LayerMask shadowgroundLayer;       // LayerMask to define what is considered ground

    private void Start()
    {
        playerPositions = new Queue<Vector3>(); // Initialize the queue
    }

    private void Update()
    {
        // Store player positions over time
        playerPositions.Enqueue(player.position);

        // Delay the shadow movement by "delay" seconds
        if (playerPositions.Count > Mathf.Round(delay / Time.fixedDeltaTime))
        {
            transform.position = playerPositions.Dequeue(); // Move shadow to the delayed position
        }
       
         // Check if grounded using groundCheck position and a small radius
        isGrounded = Physics2D.OverlapCircle(shadowgroundCheck.position, 0.1f, shadowgroundLayer);
    }
}


#

theres the shadow

naive swallow
#

Okay yeah that's teleporting. It's gonna ignore all colliders

green bison
#

how should i go about fixing it, im a complete begginer for coding

rustic arch
vestal arch
naive swallow
green bison
green bison
vestal arch
heady iris
#

nah, queueing positions makes perfect sense

vestal arch
#

because the player doesn't respect shadow objects; its position doesn't include hitting shadow objects

vestal arch
green bison
#

im gunna be honest im a complete beginner your gunna have to dumb it down a bit for me lol

heady iris
#

Ah, I see

#

It's a ~non-conventional shadow~

vestal arch
#

although, keep in mind that Update is not consistent - it's based on framerate, so if you suddenly have lag, the shadow will then have lag after the player

naive swallow
vestal arch
#

if you want it to have separate collision (for shadow stuff), it shouldn't follow the player (or well, the player's position)
it should follow the player's actions instead, aka the input that you give

#

so it should receive the inputs separately, with the given delay, and then be simulated separately

green bison
vestal arch
#

hold on, so the shadow should have an ai of its own to try to get back to the player?

green bison
#

i guess

vestal arch
#

that's a lot more complicated

naive swallow
# green bison sounds weird but i guess it should just sync up but not be able to clip through ...

Okay, so, you still want it to try to move towards a queued position, and just be stopped by things in the way.

What you're gonna want to do is use the rigid body to move instead of the transform. To get the destination, you'll want to use Vector3.MoveTowards with the shadows current position and the players current position. Pass the result of that to RigidBody.MovePosition, and that will attempt to move the object towards the players location, but will stop if it hits something

green bison
#

do you think you could help me with that please?

pliant rivet
#

Hey people, I need some help..
So I want to make a virtual pet simulator for Android and I want it to overlay other apps. I researched a bit online and I see that Unity doesn't support that type of rendering. Can I use unity to do that and if yes, how?

naive swallow
green bison
#

im not sure how to write it

#

nevermind i got it, thank you for your help

pliant rivet
dense estuary
blazing tiger
#

Asked it a while back but couldn’t think of anything better yet. What’s the best way to generate a mesh with submeshes without using nested lists?

#

Because I know it’s simple with just a Dictionary<Material, List<int>> where key is material and value is a list of triangle indices for this material

weak thicket
#

'```
public int CHANNEL = 1; // the DMX channel the M_Roll variable is on. All other variables will be on succeeding channels i. e. M_Roll_Fine on DMX channel (CHANNEL + 1)

    public VRSL_ReadBackFunction VRSL_ReadBackFunction;

    
public int[] DMXInput = new int[512];

private int[] VarChannel = new int[33]; // creates an array of length of the number of channels! cannot be edited, used for internal code

    void Start()
    {
        FoundMaterials = Rings_ShaderLink_Test2.materials;
    // calculate channel addresses! this will define which DMX channels these variables use!


        for (int i = 0; i < VarChannel.Length; i++)
        {
            VarChannel[i] = VarChannel[i]+i+CHANNEL-1;
        }

       for (int i = 0; i < VarChannel.Length; i++)
       {
         Debug.Log(VarChannel[i]);
       }


    }

    void Update()
    {

    // CONNECTING THIS TO DMX

    int[] DMXInput = VRSL_ReadBackFunction.dmxRawData; // ARRAY THIS SCRIPT USES FOR DMX, it is extracted from the VRSL_ReadBackFunction object that is linked in this object's script!


    float M_Roll = DMXInput[VarChannel[0]];
    float M_Roll_Fine = DMXInput[VarChannel[1]];

    float Ring_R = DMXInput[(VarChannel[2])];
    float Ring_G = DMXInput[(VarChannel[3])];
    float Ring_B = DMXInput[(VarChannel[4])];
    float Ring_Speed = DMXInput[(VarChannel[5])];

    float L_Roll = DMXInput[VarChannel[6]];
    float L_Roll_Fine = DMXInput[VarChannel[7]];

    float L_Light_Pan = DMXInput[VarChannel[8]-64]; //BUG: L_Pan seems to react only to roll and not the actual pan for some bizzare reason
    float L_Pan_Fine = DMXInput[(VarChannel[9])];
    float L_Tilt = DMXInput[(VarChannel[10])];
    float L_Tilt_Fine = DMXInput[(VarChannel[11])];
I am unsure whether this is the correct way of setting array values to other array values...
I am trying to set the floats to an array value that is in the position defined by another array value.

The entire script works properly, *except* for the value "L_Light_Pan", which appears to be overridden to be related to L_Roll for some reason...
I did post the part of the code that is related
#

How it should work is that the L_Light_Pan is set to a value in the DMXInput array (a 512 long array), whose position is defined as the value of the VarChannel array entry that is at the position 8.
Should I instead replace the [VarChannel[8] a-
.....
Ok...
I think I know whats happening here now...
The L_Light_Pan value is set to the DMXInput entry whose value is VarChannel[8] subtracted by 64, which happens to land on the L_Roll value of a different fixture

#

Yep...
My issue is now solved, a simple parethesis error caused this (and a negative array indicies error in two light fixtures)

molten sapphire
#

Is there a way to get mobile swipe inputs in the Unity editor/for a dev environment? I got the input system working for multiple input types (keyboard, controller & mobile swiping) but I wanted to implement a deadzone for mobile inputs in order to discard accidental inputs, and for that using an input simulator won't work for that use-case

#

I remember back when I was in college (Unity 2019) I used "Unity Remote" but it seems like the android app for that hasn't been updated in a while.

#

So I don't know if that still works.

dense pasture
#

is linq still super messy with unity?

#

memory wise

heady iris
#

using LINQ results in allocations, yes

vestal arch
#

i mean, they don't really interact?

heady iris
#

but that's not a unity thing

#

I use a fun little package called RefLinq in many places

#

It completely avoids allocations by not using IEnumerable

#

instead, you get a horrifically complicated struct type

rigid island
#

not all LINQ works the same

dense pasture
#

i was more talking about supposed issues with linq and the GC not collecting it's trash?

heady iris
#

i've never heard of that

#

that would be a catastrophic .NET bug

dense pasture
#

stuff i stumbled onto online. if its not a problem i need to be aware of then - just wanted to know if theres substance to it

vestal arch
#

i mean, gc doesn't collect until it has to

heady iris
#

what "stuff"?

#

perhaps there's a more subtle problem than what you're describing

dense pasture
#

discussions

vestal arch
rigid island
#

OP under the assumption that all LINQ functions allocate the same . Not all LINQ are heavy enough to notice much different

vestal arch
#

you're basically asking "is linq bad" here without any scope as to what aspect or severity you're referring to

heady iris
#

yeah

rigid island
#

Ofc you dont want to be slapping a heavy LINQ function in Update if you can avoid to.. stuff like that

dense pasture
rigid island
#

ah reddit, the source of knowledge

dense pasture
#

nah i'm not using it in update. i know how linq works, i dont know fully how it works within unity

#

hence why i'm asking if theres any substance to it.

heady iris
#

there's only one comment talking about memory here

They do go over that in the article, but they understate it. They say "it's OK, just don't use it every frame." What they fail to mention is that it can allocate a lot of memory. I can't remember the specifics but I had to remove LINQ from my code because it just allocated way too much memory for simple things.

oh man this is vague

#

but yes, there's a baseline amount of garbage, and then some operations are inherently more garbage-producing than others

rigid island
#

indeed

dense pasture
#

i guess the specific question is. should i avoid linq entirely or no

rigid island
#

no

heady iris
#

No.

dense pasture
#

ok. thank you!

vestal arch
heady iris
#

It's one of the first things I look at when trying to reduce allocations, though

#

(hence RefLINQ above)

#

The readability that LINQ provides is very nice.

#

I used it a lot when gathering data for an AI system

#

most of the cost came from analyzing the data

vestal arch
#

most concerns there are about perf. as with anything perf related, don't overthink it until it becomes an issue, unless you're doing something that definitely needs perf, like making a million objects or something like that

heady iris
#

so i didn't really care if it produced a bit of garbage

dense pasture
#

i'm pretty much using it for initialization of things

#

mainly because of readability yeah

heady iris
#

you should especially not worry if it's only running once

tiny star
#

someone if you know about this API keijiro
/
AICommand
I have an error nullreferenceexception

cyan mortar
#

Any of you guys know how to work with secondary entrances and exits, from one scene to another, with different spawn points and exit points? Like Mario and DKC baically

#

Corgi's Retrovania maps barely helped

vagrant blade
#

How did they implement it that made it barely help?

thin aurora
#

LINQ is a bunch of extension methods that extend IEnumerable

#

It allocates absolutely nothing for most of its methods

dense pasture
#

Read the thread

thin aurora
#

Even better, it actively tries to avoid it by trying to find the best type

heady iris
#

how clever

thin aurora
#

The Reddit post?

dense pasture
#

Yeah

cyan mortar
heady iris
#

The main challenge here is that you can't just reference a door in another scene

#

But you can certainly reference an asset that uniquely identifies the door. You could create a ScriptableObject type (maybe call it Passage), then give each door its own Passage asset.

To go somewhere, you load a scene and look for a door with the appropriate Passage.

#

you could also use a string or integer or something

cyan mortar
#

sounds interesting. I've discovered an issue with my player character's animator. I'll give it a shot when I can

leaden solstice
heady iris
#

Neat!

leaden solstice
#

Heh Goose metioned it in Honkperf already UnityChanwow

#

Though on CoreCLR Linq is getting very optimized, while Mono (thus Unity) one is less optimal

fossil obsidian
#

All the variables are appropriately set in the inspector

leaden solstice
fossil obsidian
#

After removing the singleton thing and readapting it, I realized the null reference is actually from activePlayer which is already defined here

leaden solstice
fossil obsidian
#

yea, but now I've done some logs and it says its not null

leaden solstice
#

What does stacktrace look like?

#

On your error

fossil obsidian
#

uhh it suddenly started to work becuz I've defined the stuff in a different way for testing lol

#

sry for wasting ur time .-

leaden solstice
fossil obsidian
#

yea, that was my reaction too when the system worked

pale bay
#

I have more of a design question.

I currently am working on a first person hack and slash game. Right now i'm attempting to implement a blocking system where the player can block any incoming sword attacks. I plan to make it a bit more lenient by allowing attacks to be considered blocked as long as the weapon is within the frustum of the main camera. Would this be the correct approach? are there better methods

Initially I just want to check the enemies sword collider against the players sword collider but to me that's way less forgiving and technically challenging (especially since I would heavily rely on the animation)

#

actually this seems like more of a game design question so I might move it over there

latent latch
#

animation can work, but if you were making something procedural when it comes to feedback then that becomes a little more complicated. Usually you'd have a few animations to lerp to if say an attack connects or is blocked otherwise.

pale bay
#

the complexity and the fine tuning is what I would be worried about

#

plus for example, I wouldn't want the player to get hit if the enemy hits their feet. I feel like it should be considered blocked

latent latch
#

but most games will do hitbox registration and callbacks during the animation itself

pale bay
#

I see

#

perhaps I could make the colliders more generous

latent latch
#

yeah, check out general fighting games. They give a lot of buffer room on attacks

pale bay
#

oh thats a good reference point, I haven't considered that

#

thanks!

wheat cargo
#

So... I figured out the root of the jitter and it was a combination of inconsistent framerate, RigidBody interpolation, and the camera being updated in LateUpdate.

Now the simple "solution" (not good enough for me) is to just turn off RigidBody interpolation and move the camera in FixedUpdate as well. The major problem with this, is now the game appears like it is running at low framerate because the camera only moves each FixedUpdate.

The better solution is to actually interpolate the RigidBody between FixedUpdate calls ***and *** move the camera in FixedUpdate while also interpolating it between FixedUpdate calls. This allows for a smooth follow camera even at inconsistent framerates.

#

I'd ***really *** like to use Cinemachine, but I can't figure out how to interpolate it between FixedUpdate calls without fighting it 😦

#

So custom camera controller it is, sigh

cosmic rain
wheat cargo
#

I don't think there is any way to get a smooth follow camera to work if you are moving an object in fixed update and moving the follow cam in late update, because they are essentially updating at different intervals

#

The only way I've found is to move both in fixed update and apply interpolation to both

cosmic rain
wheat cargo
cosmic rain
#

I feel like if you look at the object from a side with a static camera, you'll see it jittering as well

wheat cargo
#

That is going to be hard to setup and test but I can try

cosmic rain
#

Anyways, maybe just try getting a stable framerate instead of wasting time on this.

#

You really don't want to ship a game with unstable framerate.

wheat cargo
#

I'm more curious in the theory of it right now, and that isn't realistic on PC, with the amount of hardware configurations / in game settings options

cosmic rain
#

Using vsync or target frame rate should be enough to handle it.

wheat cargo
cosmic rain
wheat cargo
# cosmic rain If you're really curious about the underlying cause, do some logging, see the nu...

Okay so you're right, there is some jitter with a static side camera and inconsistent framerate. It is definitely not as noticeable, you gotta be like right up next to it, and I don't think that is an achieveable problem to solve. Whereas the follow camera at least can be allieviated by moving them both in fixed update and interpolating them between fixed updates. This means the camera and the object experience the jitter together in step.

wheat cargo
#

If I'm understanding correctly, this essentially "moves" the jitter to the world and it appears as if the world is jittering, but since that applies to objects further out it makes it extremely less noticeable.

#

Well that's enough theory for today lol

candid mist
#

Having an issue with my code - I've got a script that lets me rotate the bones of it's rig to turn the body. When I disable and enable the character, I can't do that anymore - it jitters and locks in place when I'm trying to rotate it. Just on its face is there anything that could be causing this that I can look into?

soft shard
candid mist
#

@soft shard it is playing an animation, but it shouldn't have anything keyed to the bones that are being animated
I'm rotating them in update - I tried shifting them to fixed update and it didn't result in any change
EDIT: Nevermind, was some functions that weren't properly in fixed update - I pushed everything there related to this function + gravity and it appears to work fine, thank you @soft shard

fiery gate
#

!collab

tawny elkBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

signal moon
#

Hi

#

A very quick question

#

I have a following function

#

But suddenly it dissapeared from button menu

hexed pecan
#

Don't think it supports multiple arguments

somber nacelle
signal moon
#

oh

#

so i just can't?

hexed pecan
#

You could pack both bools into one integer for example

#

Bit dirty

somber nacelle
signal moon
#

Thanks, i wonder why unity devs did it this way xd

soft shard
vast ember
#

I am trying to use CapsuleCast so my player does ground check. But There are 3 problems I am facing:

1.) The debug.line shows the 2 points coming above player's head and never touching the ground

2.) The Player suddenly infinitely jumps if u spam if the maxDistance is set more than or equal to 3, and not less than that (I suspect this issue might be coming because of wrong point calculation)

3.) I also noticed that my debug.line red line isn't following where my player is going. Like if I move my player somewhere else, the capsule cast debug line is still at the previous position.


float radius = capsule.radius;

Vector3 capsuleCenter = transform.TransformPoint(capsule.center); 

Vector3 point1 = transform.position + capsuleCenter - (transform.up * (capsule.height / 2 - capsule.radius)); // Bottom of the capsule

Vector3 point2 = transform.position + capsuleCenter + (transform.up * (capsule.height / 2 - capsule.radius)); // Top of the capsule

float maxDistance = 1f;

Debug.DrawLine(point1, point2, Color.red); // Draw the capsule

Debug.DrawRay(capsuleCenter, Vector3.down * maxDistance, Color.blue);
RaycastHit hit;

bool isGrounded = Physics.CapsuleCast(point1, point2, radius, Vector3.down, out hit, maxDistance, groundLayerMask);

I call this method when Player Jumps. But for debugging I am calling this method in Update() as well.

severe gulch
#

Excuse the phone screenshot, but I've been working on a building generator lately and so far I can populate a floor and 4 basic walls. A little magic from copilot and a TON of messing around, but hey I'm happy that I can at least do this.

#

Copilot got me to 70% working with this, and fooling around with my existing unity knowledge got me to here. Today I'm tackling rooms

worn crystal
#

I'm trying to use mouse to strafe camera sideways and up. It works when camera is straight angle but not if i tilt it:
Vector3 vec3 = (sensitivity * moveDelta.x) * mainCamera.right; Debug.DrawLine(mainCamera.position, mainCamera.position+vec3, Color.red, 4f); mainCamera.Translate(vec3);

#

the main camera is in root of the hierarchy, world tree

#

The debug line is absolutely showing correct direction vector, but translate doesn't follow same line

#

Like here the red lines go sideways by its rotation but camera moved up

#

hmm.. it works if i manually set position with variable 😒

#

what is wrong with translate?

leaden solstice
worn crystal
leaden solstice
woven pendant
#

hello, i have a weapon script with recoil that has Time.deltaTime implemented. But if i try at a low framerate, the weapon just shoots forwards to floating point errors. Heres my position changing scripts:

transform.position = transform.position+(posVelocity * Time.deltaTime);

and

transform.position += (((originalPosition-transform.position) * Time.deltaTime) * weaponReturnStrength);
leaden solstice
woven pendant
#

whats that mean?

#

also, i meant the weapons position on the z just goes really far really fast until it gets a floating point error

leaden solstice
woven pendant
#

not sure..

leaden solstice
#

..Why not sure if you wrote the code

woven pendant
#

im not sure which bit is bugged lol

#

i think its line 2

leaden solstice
#

Main problem is that you are not normalizing the direction

#

And also no checking for passing the destination

woven pendant
#

whats that mean..

leaden solstice
#

You have google

woven pendant
#

i have unity discord

leaden solstice
#

Good luck

swift falcon
#

I tried decals projector ( line and red color ) and somehow I got a window in screen space that do not render when in runtime, did I miss something ?

woven pendant
#

im just gonna simulate the whole transform system

#

wait no that wont work

heady iris
swift falcon
iron spade
#

Hello, I have some issues with connected anchor on hingejoint2D. Im making a rope and I dont know why when I move the rope the connected anchors go nuts and the rope go nuts with them

#

Do anyone have a tip to clamp the connected anchors ?

#

(I have autoConnectedAnchor on true)

lusty lagoon
#

Hii, i need an help with visual studio that cant connect with unity.
As you can see it wants to connect to a process.
IntelliJ doesnt work.
If i type "Rigidbody" i have this error
External Tools menu is not as usual, i dont have the option to regenerate the files

What should i do??

tawny elkBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

rigid island
#

also comment out any compile errors just incase when doing setup steps ^

lusty lagoon
#

Thank you so much i was going crazy

rigid island
slate turtle
#

public class MoveCharacter : MonoBehaviour
{
    public float walkspeed;
    [SerializeField] private string walkAnimation;
    Rigidbody rigid;
    Animator PlayerAnim;
    [SerializeField] private bool enemyInRange = false;
    private Vector3 enemyDirection = Vector3.forward;
    [SerializeField] private string attackAnim;
    [SerializeField] private float attackMoveSpeed;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        rigid = GetComponent<Rigidbody>();
        PlayerAnim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        Walk(Vector3.forward);
        if(enemyInRange)
        {
            AttackEnemy();
            enemyInRange = false;
        }
    }

    void Walk(Vector3 direction)
    {
        PlayerAnim.SetTrigger(walkAnimation);
        transform.Translate(direction * walkspeed * Time.deltaTime);
        //rigid.AddForce(direction * Time.deltaTime * walkspeed, ForceMode.Force);
    }

    void AttackEnemy()
    {
        PlayerAnim.SetTrigger(attackAnim);
        transform.Translate(enemyDirection * Time.deltaTime * attackMoveSpeed);
    }
}```

I have an issue where it doesn't continue the walk animation (still continues to move)  after performing the AttackEnemy() function
leaden ice
leaden ice
slate turtle
leaden ice
#

It doesn't look like there is any transition from the Fight state back to anything else

#

So it's no surprise it stays there

young yacht
#
private void Rotate()
{
    if (isShooting)
    {
        Vector2 input = playerInput.UI.Point.ReadValue<Vector2>();
        
        var ray = mainCamera.ScreenPointToRay(input);

        if (Physics.Raycast(ray, out var hitInfo, 100f, layerMask, QueryTriggerInteraction.Ignore))
        {
            Debug.Log(hitInfo.transform.name);
            Vector3 hitPosition = hitInfo.point;
            hitPosition.y = transform.position.y;

            Vector3 direction = (hitPosition - transform.position).normalized;
            direction.y = 0;

            transform.forward = direction;
        }
    }
}

hey guys i got this raycast and a player with a gun, wherever i shoot the player rotates towards the mouse position
my problem comes when the enemy has trigger colliders, for some reason the player doesnt rotate towards the enemy and completely ignores that area, could anyone help?

leaden ice
#

I mean

#

seems pretty obvious, you're passing this in.

#

so your raycast will ignore trigger colliders

young yacht
leaden ice
#

with Collide, it will hit triggers.

thorn ibex
#

I've got this weird bug where the player starts jittering when it reaches its Max Slope Angle

leaden ice
thorn ibex
#

This is my Grounded Check code

leaden ice
# thorn ibex

Also I think it's a major issue that you have a "static" Rigidbody that is rotating

#

!code

tawny elkBOT
leaden ice
#

please share your code in a readable way

thorn ibex
#

Ohh srry

#

This is just the Check Grounded part of the script

#

I can upload the whole Custom Character Controller but I felt that would be overwhelming

leaden ice
#

I think seeing the whole script would be much better

thorn ibex
leaden ice
#

but I think this is pretty cooked:

Vector2 Origin = (Vector2)GroundCheckPoint.position + new Vector2(xOffset, 0);```
#

even if your object is rotated you're only starting the rays along the world horizontal axis

#

so on a steep slope some of them are probably missing?

thorn ibex
#

Oh yeah so I should instead do transform.right * xOffset

leaden ice
#

you seem to be rotating your Rigidbody directly via its Transform

#

that's going to cause all kinds of problems

#

possibly including the jittering

thorn ibex
#

I tried to use RB.MoveRotation

leaden ice
#

it needs to be rotated via the RB

thorn ibex
#

But I wasn't sure how to use that with Lerping

leaden ice
#

the lerping is irrelevant

#
transform.rotation = newRotation;```
vs
```cs
rb.MoveRotation(newRotation);```
#

they both just take the new rotation

thorn ibex
#

Oh so can I just put the Lerp as a parameter?

leaden ice
#

the lerping goes into how you're calculating what newRotation is

#

it doesn't matter to the actual assignment

thorn ibex
#

Ohh KK

leaden ice
#

RB2D rotation is a float though

#

not a Quaternion

#

so you'd be just dealing with the angle

#

not a Quaternion

thorn ibex
#

Just use the z part

leaden ice
#

no

#

don't use a Quaternion at all

#

you cannot read individual parts of a Quaternion - pretend they don't exist

thorn ibex
#

Ohh it supports Quaternions as an overload

#

That works brilliantly now!

leaden ice
#

didn't know about it

worn crystal
#

i'm getting some mixed info on google if i should use destructors for custom classes that contain subobjects of also custom classes (non-gameobject or other unity types)

leaden ice
worn crystal
#

say it's a star system that has planets, when you destroy(star), what will happen to planets?

#

it's a data class

leaden ice
#

Destroy destroys the C++ unmanaged half of Unity objects

#

C# objects go away automatically when they are no longer referenced by anything else via the garbage collector

worn crystal
#

ok

#

well, there are child objects that refer their childs

#

lets hope it's smart enough then :p

leaden ice
#

there is no such concept in C#

#

there are only objects have references to other objects

worn crystal
#

Class A->B->C... refA = null;

leaden ice
#

what does "Class A->B->C" mean

#

is this an inheritance hierarchy? A bunch of things referencing each other?

worn crystal
#

yes like tree

leaden ice
#

I asked two separate possibilities there so I don't know which one you're saying yes to

#

If your object no longer has anything referencing it, it will be deleted by the garbage collector

#

you don't have to clean up objects in C# generally

#

destructors don't do that anyway - they give you an opportunity to clean up other things such as file handles or network connections

#

things that aren't C# objects.

sterile reef
#
 private void RotateTurret(Transform rotPoint, Transform target, float maxRotationAngle, float rotationSpeed)
 {
     Debug.Log("Rotating turret");

     Vector3 targetDirection = target.position - rotPoint.position; // Direction to target
     targetDirection.y = 0; // Keep rotation on the horizontal plane

     // Get the absolute world-space angle of the target
     float targetAngle = Mathf.Atan2(targetDirection.x, targetDirection.z) * Mathf.Rad2Deg;

     // Get the turret base's forward angle (starting rotation)
     float baseAngle = rotPoint.parent.eulerAngles.y;

     // Compute relative angle
     float relativeAngle = Mathf.DeltaAngle(baseAngle, targetAngle);

     // Clamp relative rotation within max left/right limits
     float clampedAngle = Mathf.Clamp(relativeAngle, -maxRotationAngle, maxRotationAngle);

     // Compute final turret angle (absolute world rotation)
     float desiredAngle = baseAngle + clampedAngle;

     // Rotate turret at a constant speed
     float newAngle = Mathf.MoveTowardsAngle(rotPoint.eulerAngles.y, desiredAngle, rotationSpeed * Time.deltaTime);

     // Apply rotation
     rotPoint.rotation = Quaternion.Euler(0, newAngle, 0);
 }

any reason why my turret still decides to take the short route outside of the clamp?

rigid island
#

those comments UnityChanLOL

sterile reef
#

so i asked gpt

#

but like i expected, still some balony

rigid island
#

what was the original problem ?

leaden ice
#

reading euler angles back from a Transform and doing logic based on them is always a bad idea

#

instead, store your own variable for this y rotation

#

and drive the rotation from your variable

#

reading euler angles back from the transform is not reliable

sterile reef
leaden ice
#

Euler angles also cannot be reliably read in isolation.

#

the Y means nothing without the x and the z

sterile reef
#

do i use SignedAngle for my solution?

#

looks good from what i see

#
private void RotateTurret(Transform rotPoint, Transform target, float maxRotationAngle, float rotationSpeed)
{
    Vector3 targetDirection = target.position - rotPoint.position;
    targetDirection.y = 0; 

    Vector3 baseForward = rotPoint.parent.forward;

    float angleToTarget = Vector3.SignedAngle(baseForward, targetDirection, Vector3.up);

    float clampedAngle = Mathf.Clamp(angleToTarget, -maxRotationAngle, maxRotationAngle);

    Quaternion desiredRotation = Quaternion.Euler(0, rotPoint.parent.eulerAngles.y + clampedAngle, 0);

    rotPoint.rotation = Quaternion.RotateTowards(rotPoint.rotation, desiredRotation, rotationSpeed * Time.deltaTime);
}

so... this does make the clamping work, but when the target is closer to the other side, the turret takes the shortcut.
how would i approach it going the long route so it doesnt clip in the ship

leaden ice
#

again use your own vartiable here

#

then you can do logic on it

neon frost
#

Can someone recommend me a video or sth for NavMesh Hiding AI. https://www.youtube.com/watch?v=t9e2XBQY4Og&t=836s this tutorial isnt working for me so by chance someone even could help me with this

Learn how to make NavMeshAgents find valid cover spots from another target object. In this video we'll specifically use a Player, but this can be applied to hide from any object - a grenade for example. Together we'll create a configurable script that allows us to refine which objects are valid to hide behind and exclude those that are not.

We'...

▶ Play video
rigid island
#

I've used it before

viscid stream
#

Someone tell me why I cant move while holding my mouse down with W A D

leaden ice
#

Your code is busted

#

As I said before.

viscid stream
#

ITS NOT

leaden ice
#

Sounds unconvincing

viscid stream
#

how can i fix

rigid island
leaden ice
viscid stream
#

okay well can you help

leaden ice
#

Can you explain your issue and share your code?

#

Nobody can help without seeing it

viscid stream
#

weol what code, I am making a VR game

leaden ice
#

The code that isn't working properly

viscid stream
#

idk whats not workin'

rigid island
#

probably the one that is supposed to make it move

viscid stream
#

nono I am saying the camera to move around in unity project

#

not in game

rigid island
#

why did you post in a code channel then

leaden ice
#

Maybe start out with that? And you posted in the code channel?

noble lake
#

Debug.Log($"Ball color is {rend.material.GetColor(Color1)}, projectile color is {p.Color}");
Ball color is RGBA(0.761, 0.223, 0.223, 1.000), projectile color is RGBA(0.761, 0.224, 0.224, 1.000)
In inspector they both have same rgba and hex. How is that possible?

steady bobcat
#

floating point precision shiz

leaden ice
#

Your material color channels are probably only stored with 8 bits - meaning 256 possible values. A difference of 1/1000 is not significant

noble lake
#

Hmm, okay, thank you all. Then what would be the best way to compare it? Round the floats?

somber nacelle
#

what is the point of comparing the colors?

leaden ice
#

What's the end goal

steady bobcat
#

everyone: WHY

noble lake
#

Ahah, basically colors are generated in runtime, when projectile has same color as the wall something happens

steady bobcat
#

real answer, add numbers up, divide by 3 and if its less than some tiny number then yay are super similar!

#

basically dont try to check if it exactly matches but if its very close

somber nacelle
leaden ice
sterile reef
#

all my homies love enums

rigid island
#

enums, so hot right now.

heady iris
#

If you genuinely need to test how close the ball's color is to the wall's color, compare their hues

#

However, you probably don't actually want that (:

stone atlas
#

I could truly use someones help with this bug I am getting. I want it so that, if my player is in the range of enemy's attack. My enemy will stop looking at its next path point and going to it and just face my player. The issue, is that it is freaking out and spam turning left and right and Idk what to do to fix this issue,

Enemy Script:
https://paste.mod.gg/neqqjdiiaves/0

Cultist enemy Script:
https://paste.mod.gg/vesakojxnuub/0

leaden ice
cosmic rain
# stone atlas I could truly use someones help with this bug I am getting. I want it so that, i...

I'd say the main issue is that you define a specific behavior right in update. You should take it out into a separate method that you can override.

Also, your approach is gonna be very limiting. Unless your ai is not gonna get any more complicated than that, I'd recommend looking into state machines, behaviour tree or maybe some more sophisticated ai frameworks, like GOAP, utility ai, etc...

stone atlas
elfin tree
#

I modified a scriptable object and have no errors in my code, yet the inspector view has not updated, even restarted unity + ide. Anyone had this before?

hexed pecan
# elfin tree

Are Triggerable and Experience marked with [Serializable]?

leaden solstice
#

What does the warning say

#

On your Triggerable fields

elfin tree
elfin tree
leaden solstice
elfin tree
#

Oh nothing bad, 1sec.

somber nacelle
leaden solstice
elfin tree
#

Ah wait squiggly lines yeah

#

Was missing this on "onAccept" and "onDeny"
[SerializeReference, SubclassSelector]

sterile reef
#

guys im so done with this godforsaken turret rotating function. nothing works, there are no explanations for the reverse rotating when the target could be reached from the other side. no YT vids, no forums, GPT is giving me sticky balls. its like no one has needed what i need and its killing me!!!!

elfin tree
#

It was saying I was missing _ for private cause they weren't serialized (I assumed)

#

thanks!

leaden solstice
cosmic rain
wheat spruce
#

If you understand how those work, then you'll understand how to make the turret rotate how you want

elfin tree
leaden solstice
#

Yeah, you can use SerializeReference which works differently

sterile reef
# cosmic rain If you need help, you should provide a better explanation(possibly with screensh...
 private void RotateTurret(Transform rotPoint, Transform target, float maxRotationAngle, float rotationSpeed)
 {
     
 }

i have a function that should

  1. rotate the turret towards the target
  2. clamp the rotation within (-)maxangle
  3. if the targetRot is within the opposite clamp, turn around (the long way)

after countless iterations i only got 1 and 2 to work. with and without stuff like RotateTowards etc.

sterile reef
cosmic rain
#

You can easily compare directions with dot product. Negative dot product would mean that the directions are "opposite"

leaden solstice
#

Show what you tried?

hexed pecan
#

I'd probably use Vector3.SignedAngle to get the Y (and X?) target angles for your turret

wheat spruce
hexed pecan
#

I disagree, you don't need to know how quaternions work

#

Just learn to use the helper functions in unity

leaden solstice
#

It’s better to know

#

Learn once and it can save you from many future issues

hexed pecan
#

You mean knowing what the x, y, z, w components do?

leaden solstice
#

What they are and how they work

wheat spruce
#

Knowing how to actually write the function is absolutely the right thing to need to know, but if you don't understand (and not even to an overly advanced degree) what you're working with, it's going to make it harder to understand how to head towards a greater goal

minor swan
#

Holy crap somebody knows how a quarternion works? How tf that’s insane

sterile reef
minor swan
#

I just accepted it stores a rotation and try not to think about it too hard

hexed pecan
wheat spruce
#

I don't think anyone actually knows what a quaternion truly is 100%, they were likely invented as a cruel practical joke

hexed pecan
#

I never had to worry about that stuff. Just know that they represent rotations, they can be combined with * (order matters), they can rotate vectors with *, and unity has a lot of helpers like FromToRotation, AngleAxis, LookRotation

somber nacelle
#

quaternions are black magic that only mathemagicians truly understand

stone atlas
sterile reef
# leaden solstice Show what you tried?
 private void RotateTurret(Transform rotPoint, Transform target, float maxRotationAngle, float rotationSpeed)
 {
     Vector3 targetDirection = target.position - rotPoint.position;
     targetDirection.y = 0;

     Vector3 baseForward = rotPoint.parent.forward;

     float angleToTarget = Vector3.SignedAngle(baseForward, targetDirection, Vector3.up);

     float clampedAngle = Mathf.Clamp(angleToTarget, -maxRotationAngle, maxRotationAngle);
     float desiredWorldAngle = rotPoint.parent.eulerAngles.y + clampedAngle;

     float currentAngle = rotPoint.eulerAngles.y;

     // WRAAAGH IT STILL SHOTCUTIHGUI RGBGFYHEGF
     if (Mathf.Abs(Mathf.DeltaAngle(currentAngle, desiredWorldAngle)) > maxRotationAngle)
     {
         desiredWorldAngle = (angleToTarget < 0) ?
             rotPoint.parent.eulerAngles.y - maxRotationAngle :
             rotPoint.parent.eulerAngles.y + maxRotationAngle;
     }
     float newAngle = Mathf.MoveTowardsAngle(currentAngle, desiredWorldAngle, rotationSpeed * Time.deltaTime);

     rotPoint.rotation = Quaternion.Euler(0, newAngle, 0);
 }

this was the closest ive come, but it still takes the shortcut

#

i delete the if() and nothing would change

hexed pecan
#

FYI, the vectors you put into SignedAngle should be first projected on the normal plane

#

I learned this rather recently (thanks vertx)

#
var projectedBaseFwd = Vector3.ProjectOnPlane(baseForward, Vector3.up);
var projectedTargetDir = Vector3.ProjectOnPlane(baseForward, Vector3.up);
float angleToTarget = Vector3.SignedAngle(projectedBaseFwd, projectedTargetDir, Vector3.up);```
#

Or in this case since it's just the up vector, you could set their Y to zero instead of projectonplane

sterile reef
#

i see

#

thats good to know

#

any other important small letters ive yet to discover (it still shortcuts)

#

OHOHOHOH i got something

// abovr is currentangle

  float speed = rotationSpeed * Time.deltaTime;
  if(Mathf.Abs(clampedAngle) > maxRotationAngle * 0.9f)
  {
      speed = -speed;
  }
float newAngle = Mathf.MoveTowardsAngle(currentAngle, desiredWorldAngle, speed);
#

its

#

going to other way

cosmic rain
sterile reef
#

but not entirely

leaden solstice
#

And negative delta is not supported

sterile reef
#

its literally Towards() everywhere

stone atlas
# cosmic rain Did you debug as you've been told?

yea, the debug is telling me that it doesnt need to flip the sprite when im to the right (when it needs to) and that it constantly flipping sprites when im to left. Im thinking of just trying to recode it from scratch

leaden solstice
#

Just make sure you +- 360 correctly for the direction

cosmic rain
stone atlas
#

ill try that.

#

!code

tawny elkBOT
cosmic rain
cosmic rain
sterile reef
#

(added after rotateAround)

#
float step = rotationSpeed * Time.deltaTime;

if(IsInRange(remainingAngle, 1.2f))
{
    step = 0;
}

if (angleToTarget < 0)
{
    step = -rotationSpeed * Time.deltaTime;
}
       
rotPoint.RotateAround(rotPoint.position, Vector3.up, step);

rotPoint.localEulerAngles = new Vector3(0, Mathf.Clamp(rotPoint.localEulerAngles.y, -maxRotationAngle, maxRotationAngle), 0);
leaden solstice
sterile reef
#

yeah

#

brother i ALMOST got

#

i nearly there

#

i can

#

feel it

leaden solstice
teal hatch
quick token
#

we cant help if you dont tell us the issue...

sterile reef
#

this concludes my day

quick token
#

real pensive

worldly hull
#

some system design questions tho , to ingame forms and dialogs

some games will have multiple steps of dialogs right? like steps 1 require u to fill in an input field for bday, step 2 will be nickname, step 3 will be username/email....etc

but when u think about it, those "input fields" are mostly the same right?

so i was trying a new approach, instead of spawning them under certain parents in groups, i will spawn them all without parents at first and group them in inspector fields

so when i want to move to next step, i just disable the one and enable the new one

#

maybe i can spawn and have less objects in game scene in this way

#

or u guys still prefer spawning them in groups with few extra objects?

latent latch
#

only cases where I will fully populate some data struct is if it's a predetermined grid / array

#

this seems to mostly be preference too so what ever you prefer honestly

#

the only downside of serializing everything directly is if serialization breaks then you're having to manually do it again

solid pagoda
#

I have had visual studio code for a while and have had this error for awhile and I just tried to get rid of it by installing the SDK and when I did I restarted my pc like the video said to do and I open it up and the error is still there I don't know how to get rid of it because I have the SDK installed i don't know what it wants could someone help me also I have uninstalled and installed C# dev kit to see if that helped it didn't

rigid island
worldly hull
solid pagoda
rigid island
rigid island
solid pagoda
#

oh what was i suppose to put sorry

thin aurora
#
- dotnet list-sdks
+ dotnet --list-sdks
solid pagoda
#

this is how i did it but nothing showed up

thin aurora
#

Then you have none installed

rigid island
solid pagoda
#

but i do have them installed because if i open up the file to download it it shows the options of repart uninstall or close

rigid island
#

did you restart pc when you installed?

thin aurora
#

If you had sdks installed it would have showed them with that command

solid pagoda
#

yes but ill try again with the restart

thin aurora
#

Alternatively follow the folder specified in my case and see if they exist for you. Otherwise you should look into reinstalling them.

regal crown
#

Hi there, anything I should know on limitations to store data on Android and iOS devices ? We come from years of PC dev and I'm just thinking of my progression layer as we started our first development for mobile

regal crown
solid pagoda
#

i just restarted my pc I still have the error should i try to repair it or uninstall it and reinstall it and then restart my pc again

#

I just looked at my output tab and it's howing this so does this mean I have to install version 6.0.0

#

if i would have the download version 6.0.0 would i have to download the ASP .NET Core Runtime 6.0.0, the .NET Desktop Runtime 6.0.0, the .NET Runtime 6.0.0, or would I have to download the SDK 6.0.100

#

I think I found the problem but idk I found out that I downloaded the x64 version of the sdk and not the x86 version

#

I fixed it, it was because I downloaded the x64 version and not the x86 version

worldly hull
# worldly hull some system design questions tho , to ingame forms and dialogs some games will ...

if u looked at the reply, u will notice some of those "parts" can be reused across different steps(groups) , the collection of the mapper must have duplicates

so, in order to refresh the UI correctly, i cannot just disable and enable components based on the step, i need to check whether the components will be used on other steps, and ignore it , otherwise the component will always be disabled

#

which is why the refresh function will be like this :

    public void RefreshStepObj(int currentStep)
    {
        List<GameObject> objToIgnore = new();

        foreach (GameObject element in Steps[currentStep].Objects)
        {
            for (int i = 0; i < Steps.Count; i++)
            {
                foreach (GameObject element2 in Steps[i].Objects)
                {
                    if (i == currentStep)
                    {
                        continue;
                    }

                    if (element == element2)
                    {
                        objToIgnore.Add(element);
                    }
                }
            }
        }

        for (int i = 0; i < Steps.Count; i++)
        {
            foreach (GameObject values in Steps[i].Objects)
            {
                if (objToIgnore.Contains(values))
                {
                    values.SetActive(true);
                    continue;
                }

                values.SetActive(i == currentStep);
            }
        }
    }```
#

it works, but as u see theres many looping going on lol, i wonder if i can simplify it more

plucky inlet
worldly hull
plucky inlet
worldly hull
#

there wont be more than 10 steps and 50 gameobjects in total

plucky inlet
#

Nah, I mean, if you fire that function in Update() , its another story (probably) than once everywhile

worldly hull
#

only when pressing buttons

#

i guess its enough lol

#

ty 👍

plucky inlet
#

Only thing that might be weird is the second for loop. you are checking if its part of ObjToIgnore and set it active then, otherwise you still set it active if its currentstep?

worldly hull
plucky inlet
#

so you could just do

values.SetActive(i == currentStep || objToIgnore.Contains(values));
worldly hull
#

ohhhhh lol

#

ty

plucky inlet
#

But it works and wont cause any harm. Do not have time to dig into it more, sorry, but you could def. make it more "elegant". But its such a small impact, if at all, so it could be a refactor for later

worldly hull
#

nah if its decent enough i will leave it as it is

plucky inlet
#

its just weird going through the current step and than again through all and again through all steps. I am sure, it could be simplified. But as you say, its decent enough

worldly hull
#

the script using that thing is a hybrid one, it can be used as editor GUI scripts on inspector and called during runtime

#

but 95% of time it will be editor scripts

plucky inlet
#

Ah, got it. so you mean, scripts running in editmode rather than editor scripts per say

worldly hull
#

mostly in editor mode

#

90% part of it is this thing

#

u put in the type (enum) u want to spawn at "spawning element" , and press rebuild UI, then it will spawn out the UI u want

plucky inlet
#

ahh, got it. So you have like a content template that you generate from with that enum, cool

worldly hull
#

if ur dialog doesnt have multiple steps, it will map automatically, if it has multiple steps, ofc everything will be manual

#

map objects urself

worldly hull
#

the most annoying part is scroll rect

plucky inlet
#

why?

worldly hull
#

not very annoying tho, but u need another pretty similar scripts for it
which is the one im working on, should be fine lol

#

the first thing i gonna ban is to allow scroll rect inside scroll rect lol

#

no way i can let u do that, even its possible

#

the alignment gonna become weird

plucky inlet
#

I mean, it can make sense to have scrollable horizontals in verticals for lists/shops/whatever

worldly hull
#

in that case i just gonna make element bigger and longer, enabling horizontal scrolls on parent 💩

steady bobcat
#

its certainly doable to have a scroll view in another but it helps when you dont mix the scroll directions

#

you have to often do stuff to prevent scrolling on the parent when interacting with a child one.

elder gust
#

is there an option to make Build profile show XR Plug-in Management? (currently using Unity6 25f1, and XR ToolKit 3.0.5)
I want to create a profile for Meta | Pico (requires different checkmarks on platform choice)

spring yacht
#

Has anyone else noticed that since 6000.0.38, it's not taking 20 minutes between each run to reload domains anymore? 😍

earnest gate
#

What do you think about Dictionary<key Dictionary<key, value>>?

somber nacelle
#

wdym "what do you think about" if you have an actual question then ask that

languid hound
#

Uhh I mean

#

It depends on the circumstance I guess??

#

I personally don't see why you would ever need this

thick terrace
#

if that kind of data structure was needed i'd rather define a struct containing a dictionary to use as the value, just for readability

chilly surge
#

Instead of Dictionary<K1, Dictionary<K2, V>> you can also do Dictionary<(K1, K2), V>. The former does have the advantage that you can use all values under one K1 like a dictionary though.

#

But yeah, I don't think I've had a situation where I need a data structure like this.

loud wharf
#

Reading the values of ContactPoint2D.normalImpulse and i saw 188,461.7.

#

When all i'm doing is moving left and right on top of boxes.

thorn ibex
#

!code

tawny elkBOT
thorn ibex
#

I've got a basic movement system in place right now that uses a Speed Difference system to ensure tight turns. However, this messes up transient forces like Jump Pads and other instantaneous effects. I'm looking to separate the force from the Run function into a Vector2 Player Vel, and calculate it separately.

#

If it was a ForceMode2D.Impulse it would be really easy, as I can just add the PlayerVel to the RB.linearVel every Update. However, it is a ForceMode2D.Force

thorn ibex
#

Like how would I make the velocity force decay over time

simple ridge
#

Hi all, what would the best channel be to discuss general system architecture?

simple ridge
#

Thanks

leaden ice
#

then... here?

simple ridge
#

Ill post here and then move it if its not in the right section.

lean sail
# thorn ibex Like how would I make the velocity force decay over time

i find it really unclear what you're asking. this message here seems to be unrelated to your one above
to make a vector "decay" over time you could just MoveTowards the zero vector
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Vector3.MoveTowards.html
in relation to the first part of your question, I think you'd have an easier time changing this logic so you aren't actually adding force to the player. Keep track of separate vectors for the different kinds of movement you'll have and then add them all to set that as the players velocity every fixed update

thorn ibex
#

Does the ForceMode change the way I add them to the velocity

#

Because I know Impulse is basically the same as directly adding it, but I'm not too sure about Force

lean sail
#

Though if you're gonna keep track of vectors yourself, its not like you'd use the ForceMode

thorn ibex
#

Yeah obv

#

Thx for the help

leaden ice
#

Doesn't look like a code related question

lusty lagoon
#

Where can i put it :P

leaden ice
lusty lagoon
#

Thank you srry

simple ridge
low kindle
#

whats the diffrent? 🙂

rigid island
#

also not code related

low kindle
tacit vine
#

hey guys question awake and the start are they called on a diffent frame?

leaden ice
#

depends on the circumstances

leaden ice
#

for example if you instantiate an object in LateUpdate, I would guess (need to test) that its Start won't run until the next frame.

rigid island
#

for example

tacit vine
#

Yeah but is this done In 2 frames

thorn ibex
#

Awake happens before Start I think

#

In the same frame

leaden ice
tacit vine
#

well it was just a discussion with my collegue about if it happens onn 2 frames or one frame

rigid island
#

in theory it should be in one frame

naive swallow
# thorn ibex In the same frame

Not quite. Correct in that Awake happens first, but the difference is Awake doesn't actually use the frame timing at all. Awake can basically "interrupt" the currently processing frame, while Start will happen before the first full frame the object exists for. So if something's spawned in on a specific frame, awake will run, the rest of that frame will run, then Start will run before the next update tick

leaden ice
#

it really depends. Start works in a funny way. You can imagine code in Unity's engine like:

void UpdateLoop() {
  foreach (Component c in updatableComponents) {
    if (!StartHasRunFor(c)) c.Start();

    c.Update();
  }
}```

It works like this for all the "update" style functions
rigid island
#

Awake works more like a constructor of the object though, start is like the single time version of Update. It depends on the Monobehavior activity

hybrid relic
#

Maybe here this makes more sense

#

Im making a "voxel" type game, aka unity cubes and i want to have the sides of the blocks that toches another block to be disabled and not be rendered, how do i go about this, i looked into voxels, but i dont think that matches for the game im making, its not like minecraft, i dont have world generation, the world is player made with cubes and limited to a 200x200 space

#

If anyone has an idea to make that more optimized like disabling renderers of covered cubes or disabling faces of overlapping faces and stuff like that or if i should go for voxels, but without chunking

leaden ice
hybrid relic
#

Thats absolutly not my thing, i make games and even multiplayer, but never worked with so many gameobjects (cubes)....

These cubes are killing me (and my pc)

leaden ice
#

for example - using a single GO per cube is probably not a good idea.

leaden ice
#

wdym by "do voxels"?

hybrid relic
#

Oh god how the f do i network that

leaden ice
#

networking and rendering seem like completely unrelated issues

hybrid relic
#

Like with minecraft and stuff

leaden ice
#

I'm saying if you look up guiides for like "how to do minecraft in Unity" you can use many of the same techniques

#

the way they render it is to generate a mesh dynamically

#

for a whole chunk

hybrid relic
#

Yes that is what voxel engines are

leaden ice
#

and render it at onces

#

If you wish to call that a "voxel engine" then sure

hybrid relic
#

I tried to avoid that as its hella complex and sigh

rigid island
#

whats a voxel engine?

leaden ice
#

though I'd disagree with you on the terminology

leaden ice
#

voxel systeM sure, not an engine

#

a voxel engine would be a completely separate thing from Unity

hybrid relic
#

Yeah naming then voxel system

#

My bad

leaden ice
#

I can't say I've watched this particular tutorial series but it looks pretty thorough

#

it probably has a lot of stuff you don't need though

hybrid relic
#

Soo yeah i thought i could avoid doing that

#

Cool

rigid island
hybrid relic
#

I wanted to keep one cube one object and just disable the renderer or sides from the not visible stuff

#

So its easier to network

#

As networking a gameobject is automatic mostly, but networking the voxels is gonna be a pain in the arse

leaden ice
#

I'm not really sure I understand what one has to do with another

hybrid relic
leaden ice
#

"networking the voxcels" wdym

hybrid relic
#

So if a player places something that the other players see that ?

leaden ice
leaden ice
hybrid relic
#

No it wont, it depends on the networking solution, ngo will implode, but the one im using is fairly good in that way as it only sends data if its changed

leaden ice
#

it's not that complicated and it's very little data

leaden ice
hybrid relic
leaden ice
#

yes it's really that easy

hybrid relic
#

Voxels looked really complex

#

Oops

leaden ice
#
  • when client joins, send them a snapshot of the whole voxel array
  • send them an update any time a block is added or removed
#

the client will always have an up to date array

#

as long as your network framework guarantees in-order RPCs

hybrid relic
#

Voxels looks like wizard fuckery to me cuz i have not much clue about rendering and editing meshrs

#

No clue actually

leaden ice
#

they're extremely simple

#

just a grid of numbers

hybrid relic
#

Ok thanks for the heads up, i will look into voxels

#

Any tutorial or article you can recommend ?

#

Cuz i mostly find minecraft garbage thats based on chunking n stuff

#

@leaden ice

leaden ice
#

you don't need to ping me

hybrid relic
#

Sorry wont do that again

leaden ice
#

Any minecraft tutorial would probably do. Just pretend your whole world is a single chunk

#

everything else is the same

hybrid relic
#

Ok perfect

#

Very helpful

#

Time to learn

patent kayak
#

Unity doesn't have built in scaling for resolutions????

#

You have to write it yourself? What??

leaden ice
#

It definitely scales automatically in general

patent kayak
#

I need the resolution of the game world to remain that

#

And not change

leaden ice
#

What does "resolution of th8e game world" mean

#

the game world is unbounded

patent kayak
#

Sometimes game worlds are not related to window size

leaden ice
#

the game world in Unity is not related to window size

patent kayak
#

For example, look at Celeste

#

The game resolution is 320*640 iirc , and the window just scales that to the middle of the screen

leaden ice
#

Not sure I follow aht you're talking about

#

but distances in the game world in Unity are not related to the number of pixels being used to render them on the screen

patent kayak
#

Okay let me put it like this

#

I need a fixed canvas size

#

That cannot change

#

Even if the window is resized

leaden ice
#

One option is to render the game to a Render Texture at a fixed resolution

#

and display it on a RawImage

hybrid relic
patent kayak
patent kayak
#

unity should have that built into the engine

naive swallow
#

It's not really a common thing

leaden ice
patent kayak
#

almost every pixel art game needs to do that skukk

hybrid relic
patent kayak
#

thankies

#

im rewriting flappy bird 1:1 and i have the game assets, but theyre fixed sizes

#

i rlly wanna play flappy bird in 2025 without all the bullcrap from the play store

hybrid relic
# patent kayak thankies

Thats why its important to ask how to archive something, not how do i do something specific, incase the specific thing is the wrong approach

patent kayak
sudden shoal
#

Sorry am new here can anyone help me on how to start creating my own game using unity game engine?

patent kayak
#

the creator took it down cos he kept getting death hreats

tawny elkBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

patent kayak
#

i already built it 1:1 in raylib, but i couldnt run it on mobile

#

so it ended up being completely useless

sudden shoal
leaden ice
patent kayak
rigid island
patent kayak
rigid island
patent kayak
#

tbh using unity makes me feel like im gonna be judged

sudden shoal
#

Pls can I make new friends here I have none😩 😩

leaden ice
rigid island
patent kayak
#

ive been a programmer for like 3 years cryplant

rigid island
#

silly to get stigma over software

patent kayak
sudden shoal
rigid island
rigid island
leaden ice
#

Ok - code architecture question - I can't seem to figure out how to efficiently store this information. Let's say you have a 2d "canvas" of sorts. For drawing a bitmap of colors on a 2D plane.
Lets say the user can place shapes down on the canvas. The shape is pretty simple - something like:

    public record Shape {
        public Color32 Color;
        public IList<Vector2Int> Positions;
    }```
I want the user to be able to place any arbitrary number of shapes down at once, and have them all be drawn. Simple enough - when the shape is placed, draw the color in all the positions, and when it's removed, remove that color.

The problem is - how to efficiently handle the cases when two or more shapes overlap? I think what I want is for the _latest drawn shape_ to always show on top of other shapes. To me it seems like I would need to store something like a sorted list of colors for each pixel, or maybe a "MaxHeap" style data structure. But it seems overkill to do this for each individual pixel. What's an efficient way to do this?
rough sorrel
#

Hi. One question, if I have a list with like 1000 elements, each with a Vector3 StartPosition,Vector3 Direction and float TimeSinceSpawn, what would be the best way to render a line for each element in its corresponding position with its corresponding direction, knowing that the list is constantly changing size please?

hybrid relic
patent kayak
#

no longer @just installed vs level@

hybrid relic
#

ye i get you, but you still got a lot to learn thats what i mean ^^

hybrid relic
patent kayak
#

of course!

#

so far im trying to figure out what im doing, this is a whole DIFFERENT WORLD (considering im coming from writing my own engine and godot)

hybrid relic
#

But i get what you mean, many label the Game as Slop Game if they see the Unity logo, without looking at the game first

#

But we should get back to code related stuff

hexed pecan
#

With GL.Lines you can draw 1 pixel wide lines pretty cheaply

hybrid relic
tawny elkBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

rough sorrel
rough sorrel
hexed pecan
#

GL.Line will look similiar to Debug.DrawLine

#

Might not be what you want for bullets

#

If the lines have just 2 points, you could just stretch an object that has a mesh renderer

#

TrailRenderer is also a thing in case you want something like that

rough sorrel
#

But having 1000s of objects each being individual might tank performance

hexed pecan
#

You could draw the meshes with one of the instanced drawing methods

#

So it would be 1 draw call

rough sorrel
#

oh okay

#

I didn't know that

#

thanks

patent kayak
#

my pixel perfect camera has like that weird gap there

hybrid relic
#

Think of Pixels Per Unit (PPU) as how many pixels fit into 1 unit of space in your game world.

#

If the PPU is lower, your game will look bigger, because fewer pixels are displayed out over the same space.

#

Did i explain that somewhat understandable

patent kayak
#

yep!

#

i fixed my issue too

#

pixel perfect camera -> stretch fill -> pixel snapping

hybrid relic
#

there you go

thorn ibex
lean sail
thorn ibex
#

It's basically just the Run function

#

That's relevant

#

And the Fixed Update

summer hawk
#

Hello so i'm having this weird "quantic bug" that happens if i start the project then launch the game, but disappear when i have the animator window opened in the editor... it's been a week kinda becoming desperate

#

has it hapenned to someone here ?

lean sail
# thorn ibex And the Fixed Update

either way you're gonna have to debug and see what vectors you're assigning. plus the issue of using AddForce as i mentioned above. Tbh your code is very unreadable. I highly suggest getting away from having as much on 1 line as u can