#archived-code-general

1 messages · Page 223 of 1

hard viper
#

shouldn’t contact normal face into the RB getting the callback?

#

i’m just trying to straighten things out before I fill everythjng with sign errors trying to “fix” it

untold siren
#

for ValueType I can just put Component or would it have to be a specific component

hard viper
#

it’s whatever type you designate

leaden ice
#

what is this a dictionary of exactly?

hard viper
#

Dictionary<string, int> myDict = new Dictionary<string, int>();

#

this is a dictionary that takes in strings, and outputs ints

leaden ice
#

what are you wanting to map to what?

untold siren
hard viper
#

whether it’s reference type or value type doesn’t make a difference

#

GetComponent is fine

leaden ice
#

what's the scope of this thing though - is this on a particular script? This would have to be per GameObject basically

hard viper
#

GetComponent is very good unless you are spamming it in like 10000 collision callbacks every frame

untold siren
untold siren
hard viper
#

use GetComponent unless you identify a method that gets called a huge number of times a frame. then you can tie a dictionary to it

#

the only time I have used a dictionary to get around GetComponent calls is when making a physics system, to avoid caling GetComponent on every single cast/contact

#

as praetor says, this is premature optimization

neon plank
#

I'm getting several serialization errors such as:

Trying to update the managed reference registry with invalid propertyPath(likely caused by a missing reference instance)'managedReferences[8989438259309051912].state.randomRepositionState', with value '-2'

I don't understand the error, I set the reference null on purpose because I didn't want to have an object there, why I get this?

pulsar holly
#

I tried instantiating an object when it falls to a certain point, but the object doesn't instantiate.

leaden ice
neon plank
somber tapir
pulsar holly
#

When should I call the bool?

somber tapir
# pulsar holly When should I call the bool?

bool called 'hasAlreadySpawned', check if it is true before spawning and when you spawn you set it to true.

if (hasAlreadySpawned == false)
{
    hasAlreadSpawned = true;
    Instantiate();
}```
limber dust
#

Okay I understand this might be a bit vague for now, but I have 2 scenes, MainMenu and Game, When I am in my Game scene and I open up my pause menu and return to the main menu via there, it obviously loads MainMenu scene and everything is fine, however the issue is when I press play again and it loads the Game scene again, my character controller does not move... the mouse look is fine, but no movement.

The weird thing is though, when I die in my game it returns to main menu and then when I press play from there and it reloads game scene, the player moves fine. So its only when going through my pause menu>mainmenu>play>loadgamescene and then no player movement.. any ideas?

knotty sun
#

Time.timeScale = 0 ?

leaden ice
somber tapir
low horizon
#
    public ref AbilityBase GetAbilityFromSlot(AbilitySlot slot)
    {
        switch (slot)
        {
            case AbilitySlot.normal:
                return ref normalSkill;
            case AbilitySlot.mobility:
                return ref mobilitySkill;
            case AbilitySlot.specialOne:
                return ref specialSkillOne;
            case AbilitySlot.specialTwo:
                return ref specialSkillTwo;
            default:
                return ref normalSkill;
        }
    }

does the ref keyword do anything different than just returning it? (AbilityBase is a class)

heady iris
#

Returning a ref is pretty special.

low horizon
#

i want to get the variable slot or something like that

#

is it possible

heady iris
#

Why not just make a dictionary at that point?

low horizon
#

oh, dictionaries

#

i totally forgot about them

#

seems to be the thing i was looking for

heady iris
#

This would indeed return one of those variables by reference, which would let someone else then assign into it

#

But I think it'd be easier if you just did a dict

low horizon
latent latch
#

Switch is actually fine if you've this many skills

untold siren
#

anyone able to assist? cinemachine input provider (using new input system) - the mouse sensitivity seems to be going extremely high at some points? I am not touching this at all via code.

heady iris
#

Is this Cinemachine 2.0 or 3.0?

#

it'll be 2.0 if you aren't sure

untold siren
#

2.9.7

heady iris
#

I think that CinemachineInputProvider tries to factor into deltaTime

#

in CM 3.0, the input provider has a checkbox to disable that

low horizon
somber nacelle
untold siren
#

and that script is only changing two values on void Awake(), not being dynamically updated or anything

untold siren
heady iris
#

3.0 is a pretty big leap from 2.0. You wouldn't want to switch just for this

low horizon
untold siren
#

not touching delta time for this unfortunately

#

Also tried changing the Input System Update mode to "Process events in fixed update" but no change

heady iris
#

Are you using the POV aim component?

untold siren
#

yuh

heady iris
#

okay, yeah, I had a peek in there

#

it scales the input by deltaTime

untold siren
#

;') damn

heady iris
#

It would be reasonably easy to fix this.

#

I usually make my "look" action absolute by adding a processor to my gamepad joystick input

#

which pre-multiplies the input by deltaTime

untold siren
#

would that be the "normalize vector2" processor

heady iris
#

No.

#

That just makes the length of the vector be 1.

heady iris
#

You'd want to turn the mouse input from an absolute movement into a speed.

craggy trail
#

how should i handle multiple enemy ais so that they arent overlapping eachother

heady iris
#

you would do this by dividing the mouse input by deltaTime, so that when it gets multiplied by deltaTime again, everything cancels out

#

this is pretty silly, but it'll make Cinemachine behave correctly

untold siren
#

how would such a thing be added peepoDetective is this a premade processor or

heady iris
#

nah, but it'd be quite short

#

hang on, let me grab it

untold siren
#

legend thank you

heady iris
#
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;

#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class DeltaTimeProcessor : InputProcessor<Vector2>
{
#if UNITY_EDITOR
    static DeltaTimeProcessor()
    {
        Initialize();
    }
#endif

    [RuntimeInitializeOnLoadMethod]
    static void Initialize()
    {
        InputSystem.RegisterProcessor<DeltaTimeProcessor>();
    }

    public override Vector2 Process(Vector2 value, InputControl control)
    {
        return value * Time.unscaledDeltaTime;
    }
}
#

this is the code I'm using

#

you'd just change this...

#

return value / Time.deltaTime;

#

amusingly, Cinemachine 3.0 has a delta time processor that does this

#

value / Time.unscaledDeltaTime;

#

Oh so THAT'S what this is for

#

It's solving this exact problem lol

#
#if CINEMACHINE_UNITY_INPUTSYSTEM
using UnityEngine;
using UnityEngine.InputSystem;
 
/// <summary>
/// This processor scales the value by the inverse of deltaTime.
/// It's useful for time-normalizing framerate-sensitive inputs such as pointer delta.
/// </summary>
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoad]
#endif
class DeltaTimeScaleProcessor : InputProcessor<Vector2>
{
    /// <summary>Compensates for varialble deltaTime</summary>
    /// <param name="value"></param>
    /// <param name="control"></param>
    /// <returns></returns>
    public override Vector2 Process(Vector2 value, InputControl control) => value / Time.unscaledDeltaTime;
 
    #if UNITY_EDITOR
    static DeltaTimeScaleProcessor() => Initialize();
    #endif
 
    [RuntimeInitializeOnLoadMethod]
    static void Initialize() => InputSystem.RegisterProcessor<DeltaTimeScaleProcessor>();
}
#endif
#

lol

#

Okay, so you could just paste this second script into your project. Just throw out the #if and #endif

#

It'll show up as an input processor

#

Add it to your pointer delta binding

#

You will need to adjust your input sensitivity downwards to compensate

untold siren
#

perfect

heady iris
untold siren
#

thank you so much

heady iris
untold siren
#

what a pain in the ass this is lmao

heady iris
#

To perfectly cancel out Cinemachine 2.0's problem, you'd need to use Time.deltaTime, instead of Time.unscaledDeltaTime

#

unscaledDeltaTime is correct -- we care about how much real time has passed

#

but it's using deltaTime

#

so, we must play by its rules!

random oak
#

I'm trying to use an Action with a Task, I did Action<Task<int>> but now how to invoke ?

untold siren
heady iris
#

well, if it's a System.Action<Foo>, you must pass it a Foo

random oak
#

yea do I make a new Task ?

untold siren
#

:(

somber nacelle
#

if you don't want to include this processor on the input action (for example if you only want it to apply to cinemachine) couldn't you just do this:

public class DeltaTimeInput : CinemachineInputProvider
{
  public override float GetAxisValue(int axis) => base.GetAxisValue(axis) / Time.deltaTime;
}
#

and then just replace the CinemachineInputProvider component with this component

heady iris
#

Ah, good idea.

#

that would confine the weirdness to strictly where it's needed

somber nacelle
#

this would only solve the issue if it is actually being caused by a deltaTime multiplication though which may not actually be the case

random oak
#

Argument 1: cannot convert from 'int' to 'System.Func<int>'

somber nacelle
#

yeah you have to pass it a func that returns an int, not just an int

untold siren
somber nacelle
#

then it isn't being caused by a deltaTime multiplication

random oak
somber nacelle
untold siren
#

this is the code I have to set mouse sensitivity, but like I've said - only being called under void Awake() so it shouldn't be affecting anything

            if (_cinemachinePov == null)
            {
                _cinemachinePov = firstPersonCam.GetCinemachineComponent<CinemachinePOV>();
                var currentSens = _cinemachinePov.m_VerticalAxis.m_MaxSpeed;
                var newSens = currentSens * sensitivity / 100;
                _cinemachinePov.m_VerticalAxis.m_MaxSpeed = newSens;
                _cinemachinePov.m_HorizontalAxis.m_MaxSpeed = newSens;
            }
            else
            {
                var currentSens = _cinemachinePov.m_VerticalAxis.m_MaxSpeed;
                var newSens = currentSens * sensitivity / 100;
                _cinemachinePov.m_VerticalAxis.m_MaxSpeed = newSens;
                _cinemachinePov.m_HorizontalAxis.m_MaxSpeed = newSens;   
            }
            
random oak
simple egret
#

Action, by definition, is a delegate type for methods that return void

#

If you need to return anything else, then you want the Func<T, TRet> delegate

#

Func<int, Task> for example

random oak
#

I see, do I use Func instead of Action or I have to use delagate keyword?

untold siren
#

this goofy ass cinemachine input provider stuff is murdering me

simple egret
polar marten
untold siren
random oak
simple egret
#

Maybe? Accepts methods that take one argument of type int, and return Task

untold siren
#

shocked I may have actually found a stupid ass solution but it works

#

it was the shitty SmartUpdate within CinemachineBrain I think

random oak
slate fern
#

Sooo should you use Update() or not? I know people who dont use it at all.

leaden ice
#

You should use Update when appropriate.

pulsar holly
#

I know I already made a similar thing, but nothing happens when a gameObject is on a certain point on the y axis.

pulsar holly
random oak
lean sail
#

Did you do anything so it wouldnt be null?

random oak
#

sorry I changed the type to string, does that matter?

somber nacelle
#

why don't you show your actual code

somber tapir
somber nacelle
#

and where is the NRE happening

random oak
#

line 15

somber nacelle
#

can you show the actual error

#

including stack trace

random oak
somber nacelle
#

okay, well most likely the issue is that something subscribed to the event is throwing the NRE not the event itself

somber tapir
random oak
somber nacelle
#

no . . . some method you have subscribed to the event is throwing a null reference exception when the event is invoked

#

the event itself is fine. you're already null checking that so it won't throw an NRE if the event is null

random oak
pulsar holly
#

I know I already made a similar thing, but nothing happens when a gameObject is on a certain point on the y axis.

somber nacelle
#

you need to share your !code if you want help. and actually describe what you are expecting to happen

tawny elkBOT
pulsar holly
#

I will when I can access my computer.

polar marten
#

sounds very cursed

dim umbra
#

Yeah, it gives that error every frame even when not in play mode, which I've never seen before

whole robin
#

I'm trying to cast a ray from a parent object that should hit a child object, but it doesn't seem to register a hit.

public LayerMask mask;

Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit, 100, mask))
{
  Debug.Log("Hit object");
  
  ...
}

I've set a new mask on the relevant child object and that same mask is set on the script component of the parent in the inspector.

polar marten
# random oak basically is trying to subscribe / unsubscribe to null event?

events are pretty rickety.

what do you expect to happen when you invoke a Func<Task, ?> event? if there are two async tasks, will they run concurrently, or will the first one added run to completion, then the second one; or, will the last one added run to completion; or if there's an exception in one, will it cause the other to fail?

polar marten
#

or is this from a chatbot or tutorial

whole robin
#

The snippet I posted is what I'm attempting to do, but not the actual script in my project, if that's what you're asking.

#

I did write it, yeah

polar marten
#

i assume you have a collider on your object that's under the mouse; that it's less than 100f away from the camera; that Vector3.Dot(ray.direction, normal of the face of the collider's geometry under the mouse) is positive aka you are outside of the collider you are trying to raycast onto; that you configured your mask correctly

whole robin
#

There's not that much more to the code than what I posted, all it does is toggle a boolean which does some stuff in the update loop, nothing that should affect the ray hit.

How do I get the normal of the face of the target collider?

leaden ice
hard viper
#

when ContactHit2Ds are made with my kinematic RBs, the .relativeVelocity doesn't match the rigidbody.velocity

#

for kinematic RBs, I guess it would just use estimated velocity from MovePosition to calculate relative velocity I assume?

polar marten
whole robin
#

Could be 😅

polar marten
#

think deeply about what it means that you are inside or outside of the collider

#

when you do the raycast

#

are you inside of it?

#

is the camera inside the collider you expect to hit?

whole robin
#

I'll take some screenshots of the scene

polar marten
whole robin
#

No no, the camera is nowhere near the collider of the object I'm trying to hit

polar marten
#

okay, is the object inside out?

whole robin
#

hmm no

polar marten
#

okay go ahead and send a screenshot of your scene. make sure your camera is visible. select the object you are trying to raycast. take a shot containing the whole inspector

#

you can try putting a sphere with an ordinary sphere collider in front of your camera, remove the mask line, and you'll observe everything works

whole robin
#

Aaah you were right to call out the mask setup...

polar marten
#

well...

whole robin
#

I had set the mask during play mode

#

classic

#

But thanks anyway, I didn't know that being inside the collider could affect it registering a hit.

#

Or the object being inside out for that matter!

rocky basalt
#

Is it possible to use ternary operator with a null check?

spring creek
rocky basalt
spring creek
#

And do you mean null OPERATOR, or is/== null

#

Either way the answer would be yes, but you should never use a null operator on a gameobject

rocky basalt
#

hmm I just wanted to do the shorthand using "?"
condition ? statement 1 : statement 2

spring creek
#

But where would the null check be? (Condition, statement1, statement2?)

#

Show what you want to ACTUALLY write

somber nacelle
#

note that the ternary operator has to return a value. you cannot just call methods that return void after the condition

rocky basalt
#

myGameObjectRef == null ? statement 1 : statement 2

spring creek
#

It's a boolean condition

rocky basalt
#

Sorry. I swear I had tried that before and got errors

spring creek
#

But as boxfriend said, you'd have to ASSSIGN it to something

#

Maybe that was the error?
That code alone is a syntax error

rocky basalt
#

Okay, I wanted to assign references in the "statement" part.. for example

myGameObjectRef == null ? myInt = 1 : myInt = 2;

spring creek
#

It's messed up

#

The assignment always is on the left

rocky basalt
#

ohhhhh

spring creek
#

myInt = myGameObjectRef == null ? 1 : 2;

#

Just to be clearer

rocky basalt
#

Thanks... For some reason I never grasped that important detail.

But yeah, I guess this won't work, becasue one of the conditions I essentially wanted to "do nothing"

#

I'm just tired of the ugly -
if(myRef == null) { myInt = 0; }

#

takes up so much space

spring creek
#

Then it would just assign itself if the condition is false. Basically doing nothing

#

Or, I mean....
if(myRef == null) myInt = 0;

rocky basalt
#

Oh nice, that could work

#

But I guess if you wanted to do something TO the gameobject you're checking the null status of, that would be impossible.. because if it's null, you can't do something to it

#

like "if gameObject != null, change it's scale. otherwise, do nothing"

spring creek
#

Ah, or yeah you could just make it != in any of the examples

rocky basalt
#

yeah whoops i switched it up

#

but i guess you can't tell the ternary to just "do nothing" in one of its statements?

spring creek
#

if(myRef != null) /*change scale*/;

spring creek
rocky basalt
#

Cool. Yeah at this point I'll acknowledge I'm splitting hairs

spring creek
#

All good haha

rocky basalt
#

For some reason I've never figured out ternary, and now I have, so thanks haha

limber dust
#

@knotty sun @leaden ice @somber tapir Thanks guys! That was it, the bool and resetting timescale to 1! Cheers!

pulsar holly
indigo pasture
#

Why am I getting a routine is null error at the startcoroutine?

    private int pointIndex = 0;
    private Coroutine pathingCoroutine;

    private void Start()
    {
        if (PathOnGameStart)
        {
            StartPathing();
        }
    }

    public void StartPathing()
    {
        if (pathingCoroutine != null) StopCoroutine(pathingCoroutine);

        pathingCoroutine = StartCoroutine(HandlePathing());
    }
pulsar holly
polar marten
#

also. always put curly braces around your if statements

plush chasm
#

should I use namespaces in unity?

spring creek
#

Just

namespace MyNamespace
{
}
plush chasm
#

always wondered if it was different in unity cuz unity doesnt make namespaces for u when u make a new script. thx

spring creek
elfin tree
#

In the New Unity Input System, is there a way to have an always on ActionMap?
Or maybe secondary, additive? For actions that would be in all ActionMaps?
Or, do people just duplicate actions for some that are in multiple maps, usually?

pulsar holly
#

I can talk now

#

So like everyone is going to ignore me.

leaden ice
dusk apex
indigo pasture
#
    private IEnumerator HandlePathing()
    {
        while (AIPathingPoints.Count > pointIndex)
        {
            PathPoint point = AIPathingPoints[pointIndex];

            float elapsedTime = 0f;

            transform.position = Vector3.MoveTowards(transform.position, point.PointTransform.position, LerpSpeed);

            pointIndex++;
            if (point.AutomaticallyStartNextPath)
            {
                yield return new WaitForSeconds(point.TimeUntilNextPath);
            } else
            {
                yield break;
            }
        }
    }

The transform isn't moving, it's moving like 2 spaces but not all the wqay to the position

#

anyone know why?

leaden ice
indigo pasture
#

But it isn'

leaden ice
#

I would expect an inner loop here where you move frame by frame towards the point until reaching it

indigo pasture
#

But it doesn't go to the next point all the way

indigo pasture
#

How would I fix it?

dusk apex
indigo pasture
#

It stops if it isn't set to start the next path

dusk apex
#

Well, yield break stops the coroutine doesn't it?

indigo pasture
#

It does

dusk apex
#

What's the problem?

elfin tree
# leaden ice Also <#763502300781477948> exists

yeah, there's a few workarounds i can think about but heh, not much cleaner than duplicating... and thanks didn't know
also found this in the meantime https://forum.unity.com/threads/layered-action-maps.788465/
which someone from unity called high priority 4 years ago

indigo pasture
#

I am making an AI controller, the way it works is you give it multiple transforms, it will loop through the transforms, move to it, and then check if you want to automatically move onto the next one or trigger it manually

dusk apex
spring creek
dusk apex
#

He'll be able to talk again in an hour or so UnityChanHuh

indigo pasture
#

I want to lerp or move smoothly to the point

spring creek
indigo pasture
#

but if theres a next point, it stops if the point says so it can be triggered manually

dusk apex
indigo pasture
#

so how do I keep the move to running so that the movement completes

#

then the if statement fires

pulsar holly
cosmic rain
spring creek
dusk apex
indigo pasture
#

How do I know when I'm at the destination

dusk apex
#

Did you write this code?

indigo pasture
#

I did

dusk apex
#

Remove the latter stuff (if-statement) if you're not ready to implement it. Seems like start and destination was implemented with no in-between (actual moving) done.

indigo pasture
#

I am implementing it

#

I can

#

I can't remove that part it's part of my planned logic

#

It's an array of points

dusk apex
#
while ...
    get ready
    //you need to implement an actual move cycle
    immediately finish```
indigo pasture
#

it loops through the points, once it gets to a point that says "Hey, don't go to the point after me"

leaden ice
elfin tree
leaden ice
#

Instead, access the maps directly through myPlayerInput.actions.FindActionMap for example

#

The concept of a "current" action map is specific to PlayerInput and it disables all other action maps

#

I generally don't use PlayerInput anyway

#

But it's useful for local multiplayer if you're doing that

elfin tree
elfin tree
leaden ice
#

There's nothing to load

#

map.Enable();

#

Is how you enable it

elfin tree
#

ahh.. got it!

leaden ice
#

Disable() to disable it

elfin tree
#

and if i use SwitchCurrentActionMap it will disable every thing except that one i assume?

leaden ice
#

Yes

elfin tree
#

and how was that relevant to local coop?

#

i did a 'bad' implementation for now for the 2nd player

#

but curious what kind of techniques you'd use

#

so I can start thinking about it, for when I do it properly

#

(or relevant documentation)

leaden ice
#

PlayerInput and PlayerInputManager work together to automatically handle user device mapping in local multiplayer

elfin tree
leaden ice
#

No

elfin tree
#

Oh okay, thanks!

#

I just realized this is still using PlayerInput, so should be fine (after re-reading what you said earlier)

leaden ice
pulsar holly
#

So uh, I put the variable in the right script, but now there's a new problem. It spawns multiple puyo when it's supposed to only spawn one. https://pastecode.io/s/keke06zy

hard viper
#

Ok, I think my timing for collision callbacks is off, based on the code I'm trying to migrate

spring creek
# pulsar holly So uh, I put the variable in the right script, but now there's a new problem. It...

Looks like you don't check which collider is entering the trigger. Just ANY collision is setting it off

Oh, and you just have it spawn two for every collision

It would be easier to read if you formatted your code better

void OnTriggerEnter(Collider other)
{
    {
        int puyoIndex = Random.Range(0, puyo.Length);
        Instantiate(puyo[puyoIndex], new Vector3(-12.5f, 5.5f, 0), puyo[puyoIndex].transform.rotation); 
    }
    { 
        int puyo2Index = Random.Range(0, puyo2.Length);
        Instantiate(puyo2[puyo2Index], new Vector3(-12.5f, 4.5f, 0), puyo2[puyo2Index].transform.rotation); 
    }
}

Those inner scopes (the curly braces) don't make much sense

hard viper
#

It looks like you have (for dynamic RBs):

  1. Fixed update starts at pos1, vel1
  2. Physics update calculates pos2, vel2. Sets rb.position = pos2, rb.velocity = vel2
  3. Physics generates contacts and callbacks at pos2
#

but that doesn't seem to be the case for kinematic RBs?

#

I'm so confused

spring creek
hard viper
#

I think I figured out how to make the manual simulation maybe work right.
At end of simulation, I know currentPos and nextPos. I rigidBody.position = nextPos; rb.velocity = Vector2.zero; Physics2D.Simulate(); before collision callbacks set rb.velocity = nextVelocity;

#

this way it generates contacts at the new position.

polar marten
#

you should switch to ECS, and try to implement your preferred physics there

hard viper
#

I'm mostly crossing the finish line

#

so no, I do not want to start over again.

#

again

#

I'm currently in the implementation stage of getting collision callbacks to match, so I don't have to refactor a huge number of classes to use my new physics API

#

at the end of the day, what I have right now only really relies on Unity to make shapes, use Box2D to calculate Cast/Overlap/Distance, and relies on unity to generate contacts/collision callbacks

delicate forge
#

hey guys. Im writting a line of code to enable a certain amount of gameobjects from a list of gameobjects. So say the list has 10 gameobjects, but I only want to load 2 of them. Could anyone possible help me in figuring out a system for this function?

somber nacelle
#

how do you determine what objects or how many of them you need to enable?

leaden ice
#
for (int i = 0; i < numberToEnable && i < list.Count; i++) {
  list[i].SetActive(true);
}```
#

for example^

somber nacelle
#

alternatively

for (int i = 0; i < list.Count; i++) {
  list[i].SetActive(i < numberToEnable);
}

if you want to make sure that you disable ones that appear later in the list

leaden ice
#

yeah - instructions are pretty unclear here

delicate forge
#

ah. you guys are awesome. I don't know how that slipped my mind. thanks

vast pumice
#
        private void UseCharacter(int characterIndex)
        {
            if (_spawnedCharacter != null) Destroy(_spawnedCharacter);

            _spawnedCharacter = Instantiate(characterPrefabs[characterIndex], transform);
            var spawnedAnimator = _spawnedCharacter.GetComponent<Animator>();
            var spawnedAvatar = spawnedAnimator.avatar;

            // Set the avatar of the main character's animator
            _animator.avatar = spawnedAvatar;

            // Destroy the spawned character's animator after setting the avatar
            Destroy(spawnedAnimator);

            GameObject rootTransform = Utility.GetChildTransformByName(gameObject, "Root").gameObject;
            rootTransform.gameObject.SetActive(true);

            _rightHand = Utility.GetChildTransformByName(gameObject, "Hand_R").transform;
            Instantiate(weaponPrefab, _rightHand);

            _animator.enabled = false;
            _animator.enabled = true;
            _animator.Rebind();
            _animator.WriteDefaultValues();


            OnCharacterSkinChange?.Invoke();
        }

Changing avatar at runtime is not working character stays in T pose. If i manually enable and disable animator in runtime its working. Any help please?

wide quest
#

Hi there!
So there is 2 problems I currently got and I think one of them can be fixed in code so that why i'm explaining it here:

Here's my problem, I am currently play testing the game I am working on (It's a maze game, something simple to try starting off with game development)
But when I go to test the game, it's as if the player is constantly getting stuck on the walls, it's like the walls are made of honey and the player has a hard time continuing moving around.

Not sure exactly what could be causing this issue, I did use a random maze generator as I really don't have the time nor patience to make a maze, wall by wall (Tried that in the past and it was not fun)
I will provide the current player movement code if needed but it's pretty much the exact same as before so nothing really got changed...

Thanks in advance! 🙂

#

Other problem (2/2) Is more of a visual issue I don't think evolves code so I will talk about that later in a diff channel to not take it off topic. ya know?

cosmic rain
wide quest
wide quest
cosmic rain
#

It doesn't make it any clearer

wide quest
#

uhh... how do I make it clearer?

#

can I somehow send you my project file??

cosmic rain
#

You can upload it somewhere, but I'm currently at work, and there's no guarantee I'll have time for that later either.

Share the code. Maybe we can guess something from it.

wide quest
#

ok one second

#

here ya go

#

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.Windows;

public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public float rotationSpeed = 2f;

private Rigidbody rb;
private Camera mainCamera;

private float cameraRotationX = 0f;

void Start()
{
    rb = GetComponent<Rigidbody>();

    //Freeze Rotation:
    rb.freezeRotation = true;
    mainCamera = Camera.main;
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
}

void Update()
{
    // Player movement
    float horizontalInput = UnityEngine.Input.GetAxis("Horizontal");
    float verticalInput = UnityEngine.Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(horizontalInput, 0f, verticalInput).normalized;
    Vector3 velocity = (transform.forward * verticalInput + transform.right * horizontalInput).normalized * moveSpeed;

    rb.velocity = new Vector3(velocity.x, rb.velocity.y, velocity.z);

    // Player rotation based on mouse input
    float mouseX = UnityEngine.Input.GetAxis("Mouse X") * rotationSpeed;
    transform.Rotate(Vector3.up * mouseX);

    // Camera rotation based on mouse input
    float mouseY = UnityEngine.Input.GetAxis("Mouse Y") * rotationSpeed;

    // Invert the mouseY input to make it feel more intuitive
    mouseY *= -1;

    // Rotate the camera up and down
    cameraRotationX += mouseY;
    cameraRotationX = Mathf.Clamp(cameraRotationX, -90f, 90f);

    mainCamera.transform.localRotation = Quaternion.Euler(cameraRotationX, 0f, 0f);
}

}

cosmic rain
#

!code

tawny elkBOT
cosmic rain
wide quest
low horizon
cyan quarry
#

Hi everyone. Im new to the discord, but I've been using unity for years.

is there any way to easily block specific raycasts?
Or am I going to have to write my own script blocking/allowing specific ones?

I have a chatbox that I want to be able to click through, but I want to still be able to scroll within it.
Which means I have to have raycasts enabled.

main shuttle
wide quest
low horizon
#

not sure about this though

#

a similar thing happened to me once

cyan quarry
limpid onyx
#

Assets\Scripts\Tool Data\WebSocketHandler.cs(3,7): error CS0246: The type or namespace name 'WebSocketSharp' could not be found (are you missing a using directive or an assembly reference?)

I don't know how to fix it, since the "using Websocketsharp" is working perfectly fine in the code itself with no errors. This only comes when i try to build.

using UnityEngine;
using WebSocketSharp;
using WebSocketSharp.Net;
using WebSocketSharp.Server;
using Newtonsoft.Json;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using TMPro;

public class WebSocketHandler : MonoBehaviour
{
    public TMP_Text uiText; // Reference to your UI Text component in Unity

    private WebSocket ws;

    private void Start()
    {
        ConnectToWebSocket();
        StartCoroutine(UpdateDataRoutine(2f)); // Update data every 2 seconds
    }

    private void ConnectToWebSocket()
    {
        ws = new WebSocket("wss://");

        ws.OnMessage += (sender, e) =>
        {
            Debug.Log("Received: " + e.Data);

            // Use Newtonsoft.Json to deserialize the JSON data received
            YourData yourData = JsonConvert.DeserializeObject<YourData>(e.Data);

            // Update the UI text with received data
            UpdateUIText(yourData.textProperty);
        };

        // If Node-RED requires authentication
        ws.SetCredentials("sfl", "password", true);

        ws.Connect();
    }
... more code here
limpid onyx
knotty sun
limpid onyx
#
  • I need the right version for 2020.3.33f1
knotty sun
limpid onyx
#

Ah it worked, thank you.

uncut vapor
#

What should I use for sending events between devices?
Checking a database is inefficient, so it networking

knotty sun
uncut vapor
#

I meant the built-in multiplayer networking

knotty sun
#

so roll your own

uncut vapor
#

Whot?

knotty sun
#

write your own networking code.
if you need bi-directional comms then you need TCP tunnelling
if it's uni-directional then a simple TCP Client/Server will do

gusty flame
#

Hey guys do you know how can i add a value to a quaternion but only on y axis (like euler angles) but without using euler angles?

#

Because i am using a Quaternion.RotateTowards function and i want object to look at another object plus a little more to the left for example

#

And normally i would do that using eulerAngles.y + value, but since i am using Quaternion i have no idea how to do it

rigid island
gusty flame
#
        Vector3 direction = target.transform.position - rotator.position;
        direction.y = 0;
        Quaternion desiredRotation = Quaternion.LookRotation(direction);
        rotator.rotation = Quaternion.RotateTowards(rotator.rotation, desiredRotation, Time.deltaTime * 350);
#

My code

rigid island
gusty flame
rigid island
gusty flame
#

Aright seems good thanks

dense swan
#

Between asking for NavmeshAgent.remainingDistance and calling Vector3.Distance(vector3a,vector3b) , which one is cheaper?

rigid island
dense swan
#

yes. I'm currently in a situation where both method serve my purpose. I just wanna trigger something if the navmeshAgent arrived. (or perhaps there is better way to do that?)

rigid island
#

i wouldnt worry about premature optimization unless you were having a real problem with performance

rigid island
#

both are valid though afaik

#

imagine a spot where its a floor above you , you're technically closer than you would be if you calculated the whole path remaining

#

so yeah it can cause issues like that I suppose

graceful latch
icy schooner
#

Hey! I need some help with a thing. I have an interaction system for npcs that will display text when talking. I already have all that. The way I do it tho is I have a queue of strings that it will display after I interact more. But I want after it has displayed one of the strings in this case the 4th in the queue for it to call a different method. Kind of like a reward so the npc gives the player gold. How should I go by doing that? I can show any kind of code needed.
Thanks

graceful latch
#

can you send it here

icy schooner
#

Wdym? Does this look like the correct one?

graceful latch
#

yeah so send the code from in that

icy schooner
#

Its a bit long so ill send this ```cs

public void DisplayNextParagraph(DialogueText dialogueText, GameObject interactedNPC)
{
currentInteractedNPC = interactedNPC;
//if there isnt anything in the queue
if (paragraphs.Count == 0)
{
if(!conversationEnded)
{
//Start convo
StartConversation(dialogueText);
}
else if (conversationEnded && !isTyping)
{
//End convo
EndConversaton();
return;
}
}

//if there is something in the queue
if (!isTyping)
{
    p = paragraphs.Dequeue();
    typeDialogueCoroutine = StartCoroutine(TypeDialogueText(p));
}
else // Paragraph IS being typed out
{
    FinishParagrapghEarly();
}

//NPCDialogueText.text = p;
if (paragraphs.Count == 0 )
{
    conversationEnded = true;
}

}

private void StartConversation(DialogueText dialogueText)
{
if (!gameObject.activeSelf)
{
gameObject.SetActive(true);
}

//This is where it decides what to look at I just need a way to reference the npc it interacted with
npcCam.gameObject.SetActive(true);
npcCam.LookAt = currentInteractedNPC.transform;
npcCam.Follow = currentInteractedNPC.transform;

//update name
NPCNameText.text = dialogueText.speakerName;

//add dialogue
for (int i = 0; i < dialogueText.paragraphs.Length; i++)
{
    paragraphs.Enqueue(dialogueText.paragraphs[i]);
}

}

private void EndConversaton()
{
npcCam.gameObject.SetActive(false);

//Clear queue
paragraphs.Clear();

//Return bool to false
conversationEnded = false;

//Deactivate text window
if (gameObject.activeSelf)
{
    gameObject.SetActive(false);
}

}```c#

graceful latch
#

add C# after the ` s

#

so it formats better

#

or cs

#

eitherway works

icy schooner
#

I did doesnt look like it changed anything. Or I just didnt notice

graceful latch
#

no put it inside the `

#

so ```C#

#

or cs

somber tapir
graceful latch
#

yeah that probably is your best bet the only other way i can think is storing whatever string your up to then using if statements to check when your on array index 4

#

or 3 since index's start at 0

icy schooner
#

Im gonna check out Yarn Spinner thank you!

graceful latch
#

good luck

#

just so you know that its good some games that use yarn spinner are: Night in the Woods, A Short Hike, Lost in Random, Dredge, Frog Detective, Button City, Escape Academy, Baladins, and Unbeatable

icy schooner
#

Only heard of dredge love the game so yeah this seems like a good choice. Thanks a lot

oak blaze
#

Hello! I am writing a (should be) simple function where my goal is to get the parent object of the selected gameobject, which sounds and should be simple, but it somehow does not give me the parent object to me. I must be missing something but i can't see what it is.

public void OnSelectEntered(SelectEnterEventArgs args)
{
    selectedChildObject = args.interactableObject.transform.gameObject;
    selectedParentObject = selectedChildObject.transform.parent.gameObject;
}
oak blaze
#

Oh woops. line 18 is the 'selectparentObject' one

leaden ice
#

then either selectedChildObject is null or it doesn't have a parent therefore selectedChildObject.transform.parent is null

#

use Debug.Log or the debugger to find out which

oak blaze
#

Oh it doesn't show it correctly that i uploaded 3 images, but if you use the arrow keys at the image you can see that selectedChildObject does have a parent object and that it is not null.

I did just figure out that when i simply drag in the gameobject in selectedChildObject that it does give me the parent, so i think it has to do something with the SelectEnterEventArgs args.

leaden ice
#

if the line you gave was the error

#

then there are only those two possibilities

oak blaze
#

yeah that's true. let me double double check it

leaden ice
#

So you are making some incorrect assumption about which object this is perhaps

oak blaze
rain minnow
#

indeed . . .

spark stirrup
#

So I have a script to pick up an object, I'm working in 2D btw, how would I stop the player from being able to put the object inside of walls? I have the collider disabled right now so it doesn't collide with the player, but even with it on it still happens. Here is my code:

https://gdl.space/ovutujatuz.cs

leaden ice
spark stirrup
leaden ice
#

you'd have to move the object either via forces/velocity on the Rigidbody, or attach a joint to it.

#

for a held object, an invisible kinematic rigidbody which you move around and the held object attached to that via a joint of some kind is decent

vague slate
#

So I have this piece of code, which is meant to go over list of Rects and remove "part" of rect if it overlaps with newRect.
But something is wrong with it and instead out of area 50-50 it creates, two areas of 5,0,45,50 and 0,5,50,45 when i try to set 0,0,5,5 rect.
What I need instead: 0,5,5,45 and 5,0,45,50 rects.
https://pastebin.com/1Yt877h3

#

basically, if I try to Set green rect on picture into red rect. I want it to create 2 blue rects instead.

spark stirrup
leaden ice
spark stirrup
#

Should I just move rb.MovePosition(holdPosition); into FixedUpdate?

leaden ice
#

i have no idea if it's that simple

#

because I didn't look closely at your code

#

but MovePosition should only be used in FixedUpdate

#

much like most physics operations

spark stirrup
#

I'll try it rq

leaden ice
#

also make sure to enable interpolation on your Rigidbody

spark stirrup
spark stirrup
#

Also if I run into a wall while holding the cube and turn around then I go flying

trim schooner
#

Press play in Unity before you start recording 😄

#

It may be enough to disable the collider on the cube when picking it up, do the animation to hold it in the correct position, then re-enable the collider

spark stirrup
fervent furnace
# vague slate So I have this piece of code, which is meant to go over list of Rects and remove...

you are working on the allocator?....
assume overlap==covers the whole rect requested (otherwise you need to "subtract" the area from requested rect and runs dfs on neighbors, it is much complicated)
then it will generate bound (free Rect in capital letter and requested Rect in small letters)
X_MIN---x_min---x_max---X_Max in x-axis and
Y_Min---y_min---y_max---Y_Max in y-axis (note that the rect maybe deformed after generation
you dont need to do any checking, the four new rects generated is
min max
X_MIN,Y_MIn x_min,Y_MAX
x_min,Y_Min x_max,y_min
x_min,y_max x_max,Y_MAX
x_max,Y_MIN X_MAX,Y_MAX (you will notice than max x, y always > min x, y)
just draw a diagram and try it yourself to see how you can use (X_MIN) (Y_MIN) (X_MAX,Y_MAX) in free rect and (x_min,y_min) (x_max,y_max) in requested rect to allocate space in refill the free list

vague slate
vague slate
#

but I guess, code can be cleaner with other checks

vague slate
#

but I got the idea, I get it how to calculate them

fervent furnace
#

if multiples adjacency free rect can used to allocate:
after each overlaps the requested AABB only generate <= two new AABBs and you just keep doing that until no new AABB is generated (ie the free rect fully cover the AABB)

spark stirrup
# trim schooner It _may_ be enough to disable the collider on the cube when picking it up, do th...

Thanks! I got it to work

void FixedUpdate(){
    Rigidbody2D rb = null; // Declare rb here

    Vector3 holdPosition = transform.position + (spriteRenderer.flipX ? -transform.right : transform.right) * holdDistance;

    if (heldObject != null){
        rb = heldObject.GetComponent<Rigidbody2D>();
    }

    if (heldObject != null)
    {
        // Make the object float in front of the player
        if (rb != null)
        {
            rb.MovePosition(holdPosition);
            rb.velocity = Vector2.zero; // Set the velocity to zero
        }
    }

    if (rb != null){
        if(rb.transform.position == holdPosition){
            if (isHolding){
                Collider2D col = heldObject.GetComponent<Collider2D>();
                if (col != null)
                {
                    col.enabled = true;
                }
            }
        }
    }
}
fervent furnace
#

idk how to type it: 0 is free rect and 1 is requested rect
000
001 1
11 here a 1 and 11 AABB are generated
000
011
11 only 11 AABB is generated
011
011 fully covered

hexed pecan
leaden ice
vague slate
# fervent furnace idk how to type it: 0 is free rect and 1 is requested rect 000 001 1 11 he...

do you mind looking into this piece as well?
This Recombine is supposed to combine rects that can be combined into one. But it seems like it's faulty and I'm not sure what's wrong.

        private struct Sorter : IComparer<RectInt>
        {
            public int Compare(RectInt x, RectInt y) => x.xMin.CompareTo(y.xMin);
        }

        private void Recombine()
        {
            // Sort the oldRects based on their xMin values
            freeRects.Sort(new Sorter());

            // Iterate through each old RectInt
            foreach (var rect in freeRects)
            {
                var combined = false;

                // Try to combine the rect with the last new RectInt in the list
                if (_tempRects.Length > 0)
                {
                    ref var lastRect = ref _tempRects.ElementAt(_tempRects.Length - 1);

                    if (rect.yMin == lastRect.yMin && rect.yMax == lastRect.yMax && rect.xMin == lastRect.xMax)
                    {
                        lastRect.xMax = rect.xMax; // Extend the width of the lastRect
                        combined = true;
                    }
                }

                // If the rect couldn't be combined, add it as a new RectInt in the list
                if (!combined)
                {
                    _tempRects.Add(rect);
                }
            }

            freeRects.CopyFrom(_tempRects);
        }
#

oh, me stuped

#

forgot to clean temp rects

#

also seems like it doesn't do very good job either

#

tons of 5x5 rects are not combined, when they should

fervent furnace
#

there are two cases
AA
BB
and
AA BB
this only do the second job

vague slate
#

🤔

#

you mean I need to sort for Y as well and do same loop?

swift falcon
#

I am trying to assign a material to a 3D object plane but the plane is still transparrent for some reason. Anyone help please?

fervent furnace
#

sorting may not be a good way to find neighbors AABB (the best way is k-d tree)
on every AABB->look for adjacency AABB with width==itself.width (or height)
and keep looping until no more combination happens
it may not be completed with just one loop: consider this
AA
BC
first you need to combine B and C to be DD
AA
DD
then combine AA and DD

vague slate
#

this is supposed to happen with 1k+ rects

#

as in, about a thousand of "allocations"

#

hmm, also not exactly sure what you mean

#

by width you mean extremums?

#

oh, you're not

#

ok, this starts to make "some" sense 😅

fervent furnace
#

this.min.x==other.min.x && max.x as well, since other must be the rect nearby
loop until no more combination:
for each rect in free list->find all its neighbor and combine (remove them from list too)
three loops, i am thinking how to do it in k-d tree
goto parent node->see if another child (since each node in kd tree have two children) can be combined with itself, do this recursively? i think the algorithm should be similar to quadtree

vague slate
#

double loop basically

fervent furnace
#

you may end up with a data structrue like this
a k-d tree with a free list (it is double linked list since you have to update previous and next child node) to connect all available child AABB in k-d tree in green (they can be used to allocate space) while the node in red means allocated space
and causes many, many bugs

vague slate
#

uuugh, I'd rather go with less efficient, but simpler approach 😅

late lion
vague slate
#

except

#

some are indeed picked already

fervent furnace
#

then just for each rect: loop through all other rect and try to combine them (remember to remove the rect that is combined)

vague slate
#

basically: existing world preallocates some rects forever. And then dynamic world allocates/frees dynamically.

late lion
#

Those are two different problems that require two different solutions. I missed some of the conversation, do you have a different method for dealing with the dynamic world?

#

It's not so important that this part (preallocating some rects) is fast, because it only happens once when the world is created, right?

vague slate
#

I find the free spot

#

and Set it just I like do with static world

late lion
vague slate
#

well, true

#

allthough

#

it's oposite of complication - simplification at a cost of performance

#

Hmm, I think I'm missing something ehre

        private static bool CanBeCombined(RectInt aRect, RectInt bRect)
        {
            if (aRect.yMin == bRect.yMin && aRect.yMax == bRect.yMax && aRect.xMin == bRect.xMax)
            {
                return true;
            }

            if (aRect.xMin == bRect.xMin && aRect.xMax == bRect.xMax && aRect.yMin == bRect.yMax)
            {
                return true;
            }

            return false;
        }
#

oooh, right

fervent furnace
#

i believe the clean up must be done after iteration otherwise the index would go wrong or some Rect will be skipped, may not true

vague slate
#

Now this should be right

            if (aRect.yMin == bRect.yMin && aRect.yMax == bRect.yMax &&
                (aRect.xMin == bRect.xMax || aRect.xMax == bRect.xMin))
            {
                return true;
            }

            if (aRect.xMin == bRect.xMin && aRect.xMax == bRect.xMax &&
                (aRect.yMin == bRect.yMax || aRect.yMax == bRect.yMin))
            {
                return true;
            }
fervent furnace
#

ah skip if i==j as well

vague slate
# fervent furnace i believe the clean up must be done after iteration otherwise the index would go...

I did slightly opposite

                for (var i = freeRects.Length - 1; i >= 0; i--)
                {
                    var aRect = freeRects[i];

                    for (var j = i - 1; j >= 0; j--)
                    {
                        ref var bRect = ref freeRects.ElementAt(j);

                        if (CanBeCombined(aRect, bRect))
                        {
                            freeRects.RemoveAt(i);

                            bRect = new RectInt
                            {
                                xMin = math.min(aRect.xMin, bRect.xMin),
                                yMin = math.min(aRect.yMin, bRect.yMin),
                                xMax = math.max(aRect.xMax, bRect.xMax),
                                yMax = math.max(aRect.yMax, bRect.yMax)
                            };
                        }
                    }
                }
#

and maybe a bit more efficient?

fervent furnace
#

yes

vague slate
#

still something is wrong

#

that blue and green haven't combined after 3 attempts

#

and I do 3 loops of those loops above

fervent furnace
#

after remove aRect it should be break since aRect no longer exists

#

it is combined to bRect

vague slate
#

oh

#

didn't change a thing for green and blue one though

fervent furnace
#

the outermost loop (not the i loop) should break only if there is no more merge, it is indefinite
try to add a boolean as mine version to see if it works

#

oh it can be finished within one iteration if you are lucky enough, the area sorted by decreased order

vague slate
#

ok, let's see

#

I guess, I'll have to move it to job

#

nah

#

green and blue are still here

#
        private void Recombine()
        {
            var combined = true;

            while (combined)
            {
                combined = false;
                for (var i = freeRects.Length - 1; i >= 0; i--)
                {
                    var aRect = freeRects[i];

                    for (var j = i - 1; j >= 0; j--)
                    {
                        ref var bRect = ref freeRects.ElementAt(j);

                        if (CanBeCombined(aRect, bRect))
                        {
                            freeRects.RemoveAt(i);
                            combined = true;

                            bRect = new RectInt
                            {
                                xMin = math.min(aRect.xMin, bRect.xMin),
                                yMin = math.min(aRect.yMin, bRect.yMin),
                                xMax = math.max(aRect.xMax, bRect.xMax),
                                yMax = math.max(aRect.yMax, bRect.yMax)
                            };
                            break;
                        }
                    }
                }
            }
        }
#

Here CanBeCombined

            if (aRect.yMin == bRect.yMin && aRect.yMax == bRect.yMax &&
                (aRect.xMin == bRect.xMax || aRect.xMax == bRect.xMin))
            {
                return true;
            }

            if (aRect.xMin == bRect.xMin && aRect.xMax == bRect.xMax &&
                (aRect.yMin == bRect.yMax || aRect.yMax == bRect.yMin))
            {
                return true;
            }

            return false;
#

I feel like my checking algo for combination is awful

fervent furnace
#

yes since you cant find nearby rect efficiently with list, i have no idea why the checking from green or blue is skipped or returning false, maybe log it yourself first to see what really happens when length==5

vague slate
#

is that the one?

late lion
#

I was always thinking that the splits would be recorded, like in a spatial tree, so it would be easy to recursively iterate over it, combining empty pairs.

vague slate
#

nah, it looks like cyan

#

hmmm. Is my algo wrong alltogether?

#

yep

#

I think something is wrong with cutting out the center part

#

and I calculate leftover rects

#

wrong

fervent furnace
#

the four rects generated by my approach should be
124
1C4
134 where C is centre

#

i think you want
122
1C4
334 ?

vague slate
#

sorry, I totally don't get your layouts. I just do math with this picture 😅

#

ok, I think I fixed it

#

ok, I think it's good now

#

3 "static" positions are cutout correct

#

and every new area is merged correctly as well

#

the only bit left for "perfect"

#

is calculate position for new rect closest to center

rough sorrel
#

Hi. Does anyone know a way to make like a fixed joint component but that it can compress but not extend?

somber tapir
rough sorrel
#

uhhh...why clamp the velocity...?

#

also how would that make it be able to compress but not extend?

somber tapir
# rough sorrel uhhh...why clamp the velocity...?

let's say you have a lever and only want it to go to the left, if the velocity.x is < 0 than it is trying to move to the right, so you reset the x velocity back to 0. You'd need to rotate the velocity to match the angle between the anchor and the object though.

rough sorrel
#

hmmm okay

#

thanks

fresh acorn
#

So I'm trying to get my language typing game to recognize foreign input... when I put in foreign characters it won't correctly detect as intended. Could it have something to do with string?

 
private void CheckInput()
{
    if(Input.anyKeyDown)
    {
        string keysPressed = Input.inputString;

        if (keysPressed.Length == 1)
            EnterLetter(keysPressed);
    }
}
leaden ice
#

what is happening and how is it different from what you expect

fresh acorn
#

So right now it works for English characters but when I try it with Japanese it won't work

mellow sigil
#

Length of Unicode characters can be longer than 1

#

What's the point of checking the length anyway?

leaden ice
#

What happens, and how does that compare with what you expect to happen?

polar marten
fresh acorn
#

I didn't know unicode characters can be longer than 1

polar marten
fresh acorn
#

ohhh

#

thank you

#

Yeah I think it has something to do with the length checking

swift falcon
#

hey everyone, im trying to make a bullet script that i can inherit from to make funky bullets, but i barely know what inheritance is, i know some things but not enough to know how to make such a script

#

is there anyone that can help me with this?

latent latch
#

Inheritance can work, but it's not always the answer.

leaden ice
swift falcon
#

cause im making a want type weapon, with 3 states, witch each 3 different working funky bullets, and setting up a base for each bullet to use would work better wouldnt it?

leaden ice
#

better than what?

#

What are you comparing to?

swift falcon
#

just making 3 different bullets

leaden ice
#

Also what does "funky bullets" mean

#

what is different about them

swift falcon
# leaden ice Also what does "funky bullets" mean

not much changes between them exept some of their properties, like 1. the bullet kind of homes in on the enemy, 2 the bullet is piecing precise and fast, while the 3rd one would be a short raged damage dealer

#

all with the same "bullet" properties right?

leaden ice
#

I would make one Projectile script with basic properties like damage, etc.
You can then just attach other components to particular bullet prefabs that modify the behavior as desired

#

I don't really see a huge benefit to inheritance here

swift falcon
#

ya think? i don't really know how to make those other components work together with the bullet though, and thats why i thought inhereting would be good

leaden ice
#

if you even need that

#

the other script can likely just handle movement for example without even caring about the fact that the Projectile component is there

swift falcon
#

my brain isnt breaining rn, im a little lost, so just make a bullet script and then a second script that does the properties of the homing for example?

leaden ice
#

yes

#

the bullet script needn't do much at all on its own

#

just have damage amount on it for example

#

maybe give it a starting velocity

#

Assuming you're using a Rigidbody

swift falcon
#

probably not, just a collider, if it hits the wall it just dies

fresh acorn
#

so Unity isn't allowing me to enter into Japanese IME mode... anyone have any thoughts as to what is happening?

leaden ice
swift falcon
#

ohh ye u right, my bad

fresh acorn
#

I can enter into Japanese mode but it won't let me switch the IME (Input Method Editor)

swift falcon
#

thnx tho!

fresh acorn
#

This is how the keyboard should be able to switch to in-game...

#

Could it have something to do with Input.inputString?

private void CheckInput()
{
    if(Input.anyKeyDown)
    {
        string keysPressed = Input.inputString;

        if (keysPressed.Length >= 1)
          EnterLetter(keysPressed);

        Debug.Log(keysPressed);
        
    }
}
#

Maybe it doesnt support foreign character input?

#

Ahh... Only ASCII characters are contained in the inputString.

#

Anyone know of an alternative to this?

deep glade
#

Please help. I'm trying to get a better understanding of code architecture. Both code which repeats, and classes which do too much are considered bad practice, right?

So... Let's say I want to make a damage system. For this I create
an IDamagable interface. Most of classes which implement this interface, will most likely reuse the same code for the damage. This seems like repeating code, which is a bad practice, isnt it?

Another way to go about it is to create a base class which contains a Damage method, and then when some object needs it, just inherit from it. But then, I need to add a "use" functionality (ability to be interacted with by the player). I add a use() method to the base class. Now all of the inherited classes have the "use" method even
when some dont need it. Isnt this also bad practice?

Which one of these is a better solution? Is there a rule of thumb for my monke brain which determines when to use interfaces and when to use inheritance? Is there a better way I'm just not thinking about? (or do I have a wrong understanding of inheritance and interfaces?)

hard viper
#

If the implementation will be very different, you want an interface

#

if implementation is (almost) identical, you want inheritance or composition

#

Example: In mario, spawners could be fixed spawnpoints, pipes, blocks. They all share a common behaviour (calling spawn and needing to be notified about death/despawn). But what they actually do when Spawn is called is totally different. You want an interface here

#

Example; Goombas, koopas, and piranha plants all do a similar thing when taking damage. (play a given death animation tied for it etc). Taking damage here should be handled by composition

deep glade
#

Thanks for the answer, will keep this in mind. One more question. Is a health component less desirable in unity? I seem to encounter inheritance and interfaces for things like damage systems etc.

hard viper
#

I would use a status component

#

One component that just handles all status (HP, status effects, modifiers etc) as a central point of contact. This Status component should be able to modify its own fields when information is passed onto it

#

should not have complex logic. Just basic accessors to read and write

#

and a little bit of logic, if the information passed into it is very spoonfed

heady iris
#

If you need to do special stuff in response to damage, consider having a common "damageable" component that raises various events

#

I've gone completely bonkers in my game. Entities just have a pile of "vitals". So, as far as the C# is concerned, they don't have "health", "stamina", "mana", etc.

Damage is a list of vital kinds and the amount to change them by. Entities that lack a certain kind of vital ignore damage they can't take.

Entities monitor their vitals and can enter special states (if the current state allows it) when they hit zero. So, if an entity's stability vital goes to zero, it plays a stumble animation.

#

...gotta admit, sometimes it's really nice to be able to just write if (entity.health <= 0), lol

#

this is an extreme composition-based approach

hard viper
#

Most of my entities have the following components:
-EntityDataHolder: holds SOs and references to key bits of data inherent to the entity needed for general game logic.
-SpawnedEntityHandler: Handles spawning, despawning, and death. It’s the main link between the entity and whatever ISpawner spawned it in.
-ObjCollision: Takes in collision callbacks and processes it in a way that can be readily used with EntityData to perform different types of logic checks.
-GenericEntityLogic: holds entity status, and processes information (usually from ObjCollision) to check for damage requests.

#

not all entities have all those components.

#

but every entity has an EntityDataHolder so we can know wtf it is and does during runtime

latent latch
#

mine usually stems like IObject -> IEntity -> IPlayer

heady iris
#

every single game I've made recently is literally just Entity

hard viper
#

My EntityData just has a bool for isPlayer

heady iris
#

with a Brain and a Locomotion

#

the entity has a state machine in it

heady iris
deep glade
#

Thanks a lot for in depth info ❤️

heady iris
#

but same idea

#
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Localization;

[CreateAssetMenu(fileName = "New Entity Spec", menuName = "Entity Spec")]
[JsonConverter(typeof(IdentifiableConverter))]
public class EntitySpec : Identifiable
{
    public LocalizedString label;
    public LocalizedString description;

    public bool isPlayer;
    public bool isBoss;
}
deep glade
#

i meant a heart, not lungs

heady iris
#

lol

hard viper
deep glade
#

but thanks 🫁

heady iris
#

it converts the direction of motion the entity wants into actual movement

#

I'm thinking I'm going to have an entire locomotion component for stuff like climbing a ladder

hard viper
#

i mean I have several different generic scripts that take full control of enemy movement behaviour. Then a specific script that lets me swap between them

#

like RailMovement, GenericEnemyWalk, KinematicFalling components. Which are all generic.

#

Then imagine GoombaBehaviour turns them on/off, so at most one is on at a time

#

understand?

#

each MonoBehaviour is a complete package, more or less

heady iris
#

ya

#

I've done almost exactly that

hard viper
#

btw I now have a new PhysicsMover component, which is basically my own wrapper around rigidbody API

#

my manual simulation is coming along nicely in time to show family for thanksgiving

#

idk if you were there when I mentioned, but in case anyone might be interested in my physics engine:
Pros:
-Reference frame support (ie parenting RBs is fully supported)
-Easy to customize force relationships (eg x sends force to y under z circumstance)
-Easy to write your own effectors
-Built in grounding, ground movement
-Would be Open Source

Cons:
-No rotation
-Certain collider types must be tied to CompositeCollider2D.
-No joints
-Only simulate one main collider per moving obj.

Neutral (neither pro nor con):
-Force does not transfer through objects (Newton’s cradle would just hard stop at first collision).
-Special collisions: Collisions try to maintain ground speed OR vertical speed. (so horizontal speed doesn’t depend on slopes, and you cant change jump height by hitting slopey walls).
-Very sequential simulation: All moving objects get evaluated in a specific sequence, where you can alter the ordering.

#

@heady iris sound interesting/worth sharing?

#

I’d call it a polite algorithm: Move colliders on “dynamic” rb assuming everything else in world is static. So one RB can never push another unless it is actually fully kinematic (or you use a script to make the illusion outside of physics step)

lean sail
#

this sounds more like a highly customized mechanic for your game, rather than a physics engine.

Force does not transfer through objects
sounds very not physics-like

hard viper
#

so, my game world breaks several laws of physics, like Newton’s 3rd law and conservation of energy

#

it mostly allows things to bump into each other, and try to resolve overlaps

#

and be in well defined reference frames

#

that last one is basically impossible in normal Physics2D

untold siren
#

trying to call a coroutine on the player script that inherits monobehvaiour, ienumerator is defined within the Sliding state for my player movement - does this imply that I need to move the coroutine to the player controller script itself? I'm currently trying to call it like this:

            Character.StartCoroutine(nameof(slideTimer));

coroutine is defined as below:

        public IEnumerator SlideTimer()
        {
            yield return new WaitForSeconds(_maxSlideTime);
            _isSliding = false;
        }
simple egret
leaden ice
#

oh

#

also that

#

yeah

#

you used the wrong name

#

why use nameof at all?

#

why not just StartCoroutine(SlideTimer());?

untold siren
#

because I need to also use StopCoroutine unless I am completely missng something here

untold siren
leaden ice
#

or better yet put a function on the script:

public void StartSliding() {
  StartCoroutine(SlideTimer());
}``` and call that
leaden ice
#

nothing about stopcoroutine requires using the string version of StartCoroutine

untold siren
#

ah damn

leaden ice
#

StartCoroutine returns a Coroutine object

#

slideTimer = StartCoroutine(SlideTimer());

untold siren
#

got it, and then to stop the coroutine I'd just do slideTimer = Character.StopCoroutine(SlideTimer()); right?

leaden ice
#

no

#

StopCoroutine(slideTimer);

untold siren
#

that makes more sense

#

my bad

#

my mind is completely ignoring the most blatant solutions lmao

#

yeah this time no errors, thank you :)

clever lagoon
untold siren
#

it be like that sometimes

#

is there any easy method I can implement a coroutine where I pass in a boolean and then after the waitforseconds is over I can reverse that bool value? kinda like with c++ when you can simply just assign a reference like &[boolToAffect] - I know that functions have got the whole out prefix but still

lean sail
#

or create a class with the bool and modify it inside the class

somber nacelle
#

i don't believe that coroutines can use out or ref parameters

simple egret
#

Yep, as enumerators compile into a big state machine (an entire class) you can't use out nor ref

untold siren
#

yeah its seeming that they cant

#

I could use a class tbh with bools which will be scalable but its a premature thing to do with where I'm at in my project

somber nacelle
#

so bawsi's class suggestion would be the easiest way. or you can pass an Action<bool> to the coroutine and just pass the bool's value when you invoke that action

untold siren
#

how would I go about using a class and then also implementing an ienumerator for it

somber nacelle
#

no instead of passing a bool to the coroutine you pass an instance of some class that contains the bool. since the class is a reference type any variable referencing that instance will be able to access the bool's updated value after the coroutine changes it

#

i still think that passing an Action for a callback would be the cleanest way to handle it though so you won't just be polling the bool for changes, you would instead have a method that just reacts to the change when the action is invoked

untold siren
#

I get it but I don't at the same time

somber nacelle
#

what part of that do you not understand?

untold siren
#

so what I ideally want is

bool1 = false
bool2 = false
bool3 = false

starttimer(bool1)

after the timer ends the bool I've passed through will now be true

#

but a callback / class doesn't seem to kinda explain to me how I'd implement that within a coroutine

somber nacelle
#

for the class you just do something like this:

public class TimerBool { public bool TimerRunning; }

//in your monobehaviour
private IEnumerator StartTimer(TimerBool timer)
{
  //do you stuff
  timer.TimerRunning = true;
}

and since TimerBool is a reference type, anything referencing that instance will have access to the same bool variable inside of that class

heady iris
#

yep. this is what the Volume framework does, for example

#

it has a bunch of classes that hold a value

#

You can get more elaborate with it, too. For example...

#
public class TimerBool
{
  private bool _value;
  public bool Value
  {
    get => _value;
    set
    {
      if (_value != value)
      {
        OnChange?.Invoke(value);
        _value = value;
      }
    }
  }

  public event System.Action<bool> OnChange;
}
#

now you can subscribe to changes to this shared value

somber nacelle
untold siren
#

I am still confused lmao

somber nacelle
untold siren
#

ok right

somber nacelle
untold siren
#

so my movement stuff follows a finite state machine layout
I want to have bools to check if the cooldown is over for certain things e.g.:

  • canSlide
  • canJump
  • canWallrun

etc etc

and instead of having to do a coroutine for each one and their cooldown length, I'm wanting a single coroutine where I can pass through the boolean I want to be affected alongside the duration the timer runs for
so if I were to say, want to enable sliding
then
I'd like something like:

private IEnumerator movementTimer(bool boolToAffect, float timeToTake)
{
    yield return new WaitForSeconds(timeToTake);
    boolToAffect = true;
}

but with the above definition, that'd only affect the value of the local var due to it being a reference and not it being the physical value

basically wanting an equivalnce of:

private IEnumerator movementTimer(ref bool boolToAffect, float timeToTake)
{
    yield return new WaitForSeconds(timeToTake);
    boolToAffect = true;
}

which isn't doable due to how coroutines / ienumerators work

somber nacelle
#

okay so both of the solutions that were suggested would solve this

heady iris
#

You will need to replace your bool fields with BoolCountdown fields.

#

if you want to go that route

#

Personally, I wouldn't even bother if you have such a small set of fields that need toggling.

#

Or I'd just make an enum type to control things.

untold siren
heady iris
#

along with a switch statement to target the relevant field

fiery path
#

if i was you id replace bool fields with BoolCountdown fields @untold siren

untold siren
#

I know you're trying but that still doesn't make sense to me lol

heady iris
#
DelayedSet(MovementFlag.Jump, true, 0.5f);
#

e.g.

somber nacelle
#

Actions might be a bit easier and more versatile.

private IEnumerator Cooldown(Action cooldownComplete, float time)
{
  yield return new WaitForSeconds(time);
  cooldownComplete?.Invoke();
}

then just use it like

StartCoroutine(Cooldown(() => canSlide = true, 0.5f));

You could even reuse that for things other than just flipping a bool's value too

untold siren
heady iris
untold siren
#

however pepeLaugh

     Character.StartCoroutine(Character.BoolCooldown() => Character.canSlide = true, 0.5f);
heady iris
#

that syntax is all kinds of messed up

untold siren
#

wait no I;m a dumbass

#

missing parantheses

untold siren
heady iris
#

Character.BoolCooldown() is invoking a method on Character named BoolCooldown

#

then the parser crashes into =>

somber nacelle
#

yeah they just missed the opening ( for the anonymous method so it made the entire thing look weird

heady iris
#

oh, is this meant to be

#
Character.StartCoroutine(Character.BoolCooldown(() => Character.canSlide = true, 0.5f));
#

I'd hvae to see whatever BoolCooldown is, I guess

somber nacelle
#

yeah i think they took my suggestion of passing an action

heady iris
#

and I see now that Character is a variable, not a type name

untold siren
somber nacelle
#

I would name it something other than BoolCooldown though because it doesn't have to be a bool anymore

#

This is basically just unity's Invoke method but with delegates instead of reflection to find a method

heady iris
#

yep

#

which is pretty reasonable

#

I'd call it Delay or DelayedAction

untold siren
#

got it working, thank you guys

#

for checking new input system stuff I can replace:

            if (JumpAction.triggered)
                isJumping = true;
            if (SlideAction.triggered)
                isSliding = true;

with something like:


isJumping = JumpAction.IsPressed();
isSliding = SlideAction.IsPressed();

right?

heady iris
#

If the InputAction is a "button" type, then that'll tell you if it's currently pressed, yes

untold siren
#

got it, thank you

simple egret
#

And more generally, any pattern that looks like this

if (condition)
  thing = true;
else
  thing = false;

Can be shortened down to thing = condition;

heady iris
#

the former sets isJumping to true if you trigger the action

#

and does nothing otherwise

#

the latter sets isJumping to true if you're holding the button and to false if you aren't

#

Those are not equivalent. The latter resets the variable the moment you let go.

simple egret
#

They probably have other conditions that check for button release somewhere below

untold siren
#

assuming to much of me OMEGALUL in the process of getting this stuff implemented I completely forgot to add the button release check

#

only just realised now that I'm implementing cooldowns

silk horizon
#

Localization

golden hedge
#

Heya ive run into a bit of a wall. Say Im making a game that has "weapon groups". There are six total that the player can assign to any button. This comes into the form of a bool[6]. Every weapon will have it stored. So the question is. How should I go about saving all the weapon groups to a file to load and assign to the appropriate weapons later?

heady iris
#

e.g. weapon 1 fires when buttons A/B/C/D are pressed and weapon 2 fires when buttons C/D/E/F are pressed

golden hedge
#

I just need to store what the player sets

heady iris
#

Are the weapons fixed, or can you also customize which weapons you have?

golden hedge
#

Im thinking json might work. But ive never messed with it, so could I use it or somthing simaler?

heady iris
#

yes, you ought to be able to serialize this data into a JSON file, then read it back in later

golden hedge
heady iris
#

okay, so you'll need to remember both which weapon is in the slot and which groups the weapon has been assigned to

golden hedge
heady iris
#

I'd suggest creating a save data class

#

You'll save the game by creating an object and putting data into it

#
[System.Serializable]
public class SaveData {
  public List<WeaponData> weapons = new();
}

[System.Serializable]
public class WeaponData {
  public string id;
  public List<bool> groups = new();
}

It could look like this, for example

#

This would be seprate from the classes you have already

#

You wouldn't be trying to serialize your Weapon class directly

golden hedge
#

Hun Good idea

#

Ill let you know if all goes well

#

Thanks in head of time mate!

prisma hatch
#

hey lads, can anyone help me with this

1/ A script that will be added onto an object.
(Addendum : The script will have a float variable named Duration)

2/ It will check if object already has the same script (except itself).

3/ It will proceed to increase the previous one's Duration and delete itself.

#

Many thanks in advance

hexed pecan
#

Why would the new script change the old one's duration though?

#

Is the idea to like merge duplicate components?

prisma hatch
#

yeah

#

to merge

#

thanks for the reply btw

hexed pecan
#

Is it like a status effect/buff or something?

prisma hatch
#

yeah

#

exactly

hexed pecan
#

You can do it with trygetcomp like I said but it would be good to have a script that manages that stuff

#

And keeps current effects in a list

prisma hatch
#

true, I'll look forward into it

#

working wonderfully, appreciate the help mate

#

have a nice day

hexed pecan
#

Np, you too 👍

fresh acorn
#

So Im trying to convert English letters to Japanese ... what's the best loop to go through the input and replace the respective characters?

    private void CheckInput()
    {
        if (Input.anyKeyDown)
        {
            string keysPressed = Input.inputString;
            
            // adding character to the string
            japaneseText += Input.inputString;

            Dictionary<char, string> kana= new Dictionary<char, string>
            {
                {'a', "あ"}, {'i', "い"}, {'u', "う"}, {'e', "え"}, {'o', "お"}
                //{"', "か"}, {'ki', "き"}, {'ku', "く"}, {'ke', "け"}, {'ko', "こ"},
            // Add more mappings as needed
            };

            if (keysPressed.Length >= 1)
            {
                //EnterLetter(keysPressed);
                EnterLetter(japaneseText);
            }
        }
    }
dusk apex
#

Maybe use a serialized dictionary asset from the unity store - there are free ones.

quartz folio
#

Though I suppose not if you're doing the second line with dual characters

#

For that you'd better be using a stringbuilder and a loop

rugged tinsel
#

I have a script to select gameobjects. It selects them when i click on the screen and it sends a raycast and returns the hit gameobject. I have 2 joysticks (canvas) and some ui elements (ui toolkit) on my screen. If i click on them, the raycast shoots and selects the gameobjects behind them. Any idea how to prevent this?

open charm
#

So Im tryng to make a reflector in unity 2d and i am unsure how to go about it

#

My initial plan was to have a prefab particle and just add some collider to it

#

And when projectiles hit this collider they move at the opposite direction

#

The problem is the collider of the particle is a bit weird

#

since its a bit rounded, the way the projectile moves after getting reflected is not as intended

#

I was also planning to add a sperate collider but the issue i find is that the collider does not follow how the animation looks

tall belfry
#

I have two scroll areas side by side. The left one cuts of the top element the right one works correctly.
Their setup is identical. Please Help

I have tried moving the "ReportCards" with the Rect tool but it just snaps back.

heady iris
#

they might be causing unreliable behavior

#

The content size fitter should go as high up as possible

#

basically, if your parent has a Layout component, you should not have a Content Size Fitter component

#

it should go on your parent instead

tall belfry
#

Had tried that, that doesn't fix unfortunately

heady iris
#

Your scroll areas should have a layout component on them.

#

You need an unbroken chain of Layout components all the way down

#

Otherwise, the child components won't be able to ask for the appropriate amount of space

#

I might be mistaken. Let me check that.

#

ah, yes, I see how I've done this before

#

gimme a few minutes

#

Here's your problem.

#

Your left scrollrect has the wrong viewport

#

Also, I put my content size fitters on the child of the Viewport transform, so it looks like this

#
  • Scroller <- Scroll Rect
    • Viewport <- Mask, Image
      • Content <- Content Size Fitter, Vertical Layout Group
#

also, if you have other questions about this, they should go into #📲┃ui-ux

indigo pasture
#
        Camera cam = globalPlayerManager.GetPlayerCamera();
        var objRotation = Quaternion.LookRotation(obj.transform.position - cam.transform.position);
        while (cam.transform.rotation != objRotation)
        {
            cam.transform.rotation = Quaternion.Slerp(cam.transform.rotation, objRotation, 2f * Time.deltaTime);
        }

Is this good code for smoothly looking the camera?

rigid island
#

use cinemachine

heady iris
#

I guess it works, but yes, you should consider using Cinemachine for camera control

indigo pasture
#

well my project is already programmed and being worked on

#

with camera logic

rigid island
#

its one of those, why reinvent the wheel if someone made these features already

indigo pasture
#

well I like programming things myself since I'm a solo programmer, feels lazy

heady iris
#

i'm also a solo programmer

#

i ain't reinventing the wheel

indigo pasture
#

I like reinventing the wheel to understand the wheel

heady iris
#

your code will behave very differently at different framerates as-is

latent latch
#

If I use cinemachine I use it specifically for these specific cases with smoothing and not having to deal with jittering

rigid island
#

seriously its butter smooth

tall belfry
heady iris
#

I still find plenty of ways to cause jittering 🫠

rigid island
indigo pasture
#

how easy is cinemachine to integrate into an existing project

heady iris
#

the deoccluder has been very useful

indigo pasture
#

my code is crashing Unity

rigid island
#

literally no code

#

its a package

indigo pasture
#

and I don't feel like figuring it out

rigid island
#

plug in a target and done

hexed pecan
rigid island
#

I mean if you enjoy coding features people already made better, more power to you

heady iris
rigid island
#

I prefer having smarter people make the features I need and I just implement them

#

to each their own

heady iris
#

i just really like using cinemachine

#

it solves a complex problem so that i can make my dang game

rigid island
#

100% if you just need results, thats why cinemachine exists

hexed pecan
#

Doing camera stuff is a great way to learn about order of execution and possibly physics if thats involved

rigid island
#

sure. valid point never said otherwise

heady iris
#

I got to learn about execution order when getting Cinemachine to play nice with third party plugins 😛

latent latch
#

camera stabilization is a pain

#

but if you've a flat terrain then anything is fine lol

hexed pecan
#

Oh yes, there will be pain 😄

heady iris
#

I also write plenty of camera code anyway

#

when I want to set up a very specific shot

hard viper
#

my physics system is using non-alloc .Cast methods for casting, and it gives me options for both arrays and lists... does it really make much difference?

#

array forces me to set a max size in advance. List auto-resizes.

light egret
#

!vc

tawny elkBOT
#
Using version control in Unity

Unity Version Control

git Git

Get the latest .gitignore file from here. It should be placed at the root of your Unity project directory.

latent latch
#

like, the idea is to set a large capacity

fervent furnace
#

i think that the query will returns only array.length elements if you use array and you will miss some XXXInfo.
idk why it does not take a ref array into it, since it is the same as list

latent latch
#

it'll populate up to the max, but the idea is to add a larger buffer size than you need

#

mem is cheap anyway ;p

#

List can work too as long as you don't trim the excess. Create a small buffer of elements and then let the list decide the capacity if it needs to extend over the max.

heady iris
leaden ice
#

It's definitely from LINQ yes

heady iris
#

That will mega-allocate for sure

fervent furnace
#

i think he means his physics system calls the Physics.XXXCast

heady iris
#

Oh, I see

#

I thought you were talking about casting arrays and lists

#

That makes more sense

latent latch
heady iris
#

ah, and this one lets you use both static arrays and lists

#

Using List seems more convenient, and it won't reallocate unless it actually needs to

leaden ice
#

I usually reuse a single static List for all physics queries across my entire project 😆

heady iris
#

i've done that, yeah

#

the power of single-threading!

fervent furnace
#

my class have their own static buffer

heady iris
#

it'd be really nice if the other physics methods could also take a list

hard viper
#

i tried arrays before. Moved to lists. Now idk if I should optimize by going back for some choice arrays

heady iris
#

I would not expect much of a difference

hard viper
#

figured. worth asking

quick elbow
#

Does Unity support use of DLL's built with C#10?

#

I know Unity itself doesn't support C#10, but I'm not sure for DLLs

hard viper
#

I would assume not, but idk for sure

#

unity barely supports C#9

#

CompositeCollider2D.edgeRadius only seems to impact the collider when it is in Outline mode. Is there a workaround to get it to work with Polygon mode?

unborn elm
#

Hi,
I have a wierd error that I havent come across before.
I have set up a prefab and a runtimeIntilizeOnLoad on a static class so that all my necessery objects are loaded no matter what scene I use. This is all working as inteded.
However when I load a scene for a second time it seems like these cant find in the scene.
I have a simple funtion

GameObject.Find("playerParent").transform)

that is beeing called when

(SceneManager.GetActiveScene().isLoaded)

This works the first time the scene is loaded but not the second.
I have never had this problem before and therefore im thinking that the fact that I use the runtimeInilize somehow is to blame
The "playerParent" is visable in the inspector but I still get a nullref error

hard viper
#

I would not call GameObject.Find

static matrix
#

whats a good way for making a lot of different areas of the world respond when clicked?
like if I have an image, and I want something different to happen depending on where you click it, creating a ton of buttons or collidiers does not seem like the correct solution

hard viper
#

that method is a noob trap

hard viper
static matrix
#

I remember I was causing thousands of lag frames because I was calling Find in update on hundreds of objects and never looked at the profiler 💀

#

I fixed that

hard viper
#

.Find is a noob trap

static matrix
hard viper
#

you want to get the reference normally, not with .Find

unborn elm
static matrix
#

and if you start having perf issues it should be the first thing to optimize

hard viper
#

I have a Singleton that has references to key gameobjects. This singleton is destroyed on load

static matrix
#

smort

hard viper
#

like, WorldGameObjectCentral has direct references to: the main Grid for my game world, my player gameObject, the goal flag object, the starting position object

#

just a few really critical and static things

spring creek
#

Don't cross-post.
One channel per question please

unborn elm
rigid island
unborn elm
#

but if its a singelton it cant be on a gameobject

#

so how does that work?

#

or is it just a static refference?

rigid island
#

unity doesnt really have traditional DI system , singleton here you still need a gameobject somewhere

static matrix
#

whats the key differences between Awake and Start and which one should I use?

rigid island
#

I suppose think of it like a constructor that runs at least once

static matrix
#

so why wouldnt i use Start

rigid island
rigid island
# static matrix so why *wouldnt* i use `Start`

because lets say you have a singleton happening then you have another script that subscribes to something on that singleton, if you put both in awake/start you get a null ref at some point because order is not guaranteed, having awake doing Init singleton first and then others sub on Start/OnEnable you guarnteed no null ref from Singleton initialized in awake.. Hope is not confusing example..

static matrix
#

no, that makes sense

rigid island
#

😅 the link in docs explains a bit more also some key differences

#

like when objects are disabled

#

etc

unborn elm
rigid island
rigid island
unborn elm
# rigid island I haven't seen your post, which line is null ref

Hi,
I have a wierd error that I havent come across before.
I have set up a prefab and a runtimeIntilizeOnLoad on a static class so that all my necessery objects are loaded no matter what scene I use. This is all working as inteded.
However when I load a scene for a second time it seems like these cant find in the scene.
I have a simple funtion

GameObject.Find("playerParent").transform)

that is beeing called when

(SceneManager.GetActiveScene().isLoaded)

This works the first time the scene is loaded but not the second.
I have never had this problem before and therefore im thinking that the fact that I use the runtimeInilize somehow is to blame
The "playerParent" is visable in the inspector but I still get a nullref error

rigid island
unborn elm
#

Sorry can't atm, on my way from work now so only on my phone

rigid island
#

ah well it would be easier to debug if we can see more info

unborn elm
#

But hopefully a singleton with a ref might solve the problem

rigid island
#

Find method are to be avoided

unborn elm
heady iris
#

or are you calling DontDestroyOnLoad on the loaded object?

unborn elm
#

Yeah it's beeing loaded with the scene and can be found in the inspector

#

I have a don't destroy on load on my system prefab that I instsciate with a static class. So the object using the find is don't destroy on load

heady iris
#

oh, I see; the object you spawned is trying to find a scene object

unborn elm
#

The object beeing spawned is basically a gamemanger, scenehandler etc.
This is beeing spawned when the first scene is loaded and the root object of the prefab had don't destroy on load.
Then when a certain scene is loaded, it looks for a game object ("playerParent" ) that Is suppose to be used as a parent for other objects that are instanced in that scene

wide mural
#

why does only directional light produce light and not spotlight? is there smthg im forgetting to do?

heady iris
#

a directional light has no falloff

#

a spotlight has a finite range, and also gets darker as you get further away

wide mural
heady iris
#

also, if you already have a sun light, the spotlight is probably just way too dim to matter

#

is this an HDRP project?

wide mural
#

URP

heady iris
hard viper
#

anyone know about edge radius for PolygonCollider2D in Physics2D/Box2D?

#

my CompositeCollider2D can have a working edgeradius in Outline mode, but not Polygon mode.

#

and PolygonCollider2D don’t have an edgeRadius field, which I think is linked

#

would anyone know if there’s a way to make a polygon collider that also has a radius?

#

it needs to be solid in interior

#

i guess my plan is to just make two colliders for every tilemap… lol

wheat cargo
#

Is there a simple way to get line numbers to show in logs for a release build?

hard viper
#

you can make your build in Debug mode, so it can show debug logs

wheat cargo
hard viper
#

idk then. sry

wheat cargo
#

plus I'm seeing different behavior in release that is not happening in development build

hard viper
#

are you doing any real code in Debug.Assert?

#

I remember once noticing that I had a Debug.Assert with a .TryGetValue or TryGetComponent, and then I used the value. Which blew up in my face

#

the whole line gets removed

wheat cargo
hard viper
#

keep an eye out for any Debug.Assert with any methods with an “out” or “ref” parameter

#

that’s bad juju

simple egret
#

what?

#

It'll be the same as an if statement, Assert takes a bool value

hard viper
#
if (col.forceSendLayers == 0) {```
#

that if statement will give a NRE in final build

simple egret
#

Ah for builds of course

hard viper
#

that is what I noticed

simple egret
#

As the name suggest, Debug.Assert is for debugging