#πŸ’»β”ƒcode-beginner

1 messages Β· Page 660 of 1

buoyant schooner
#

Thanks so much πŸ™‚ This has saved me so much pain :))

rich adder
buoyant schooner
#

ye, I was just trying to prototype my structure for the rest of my game

rich adder
#

oh and Start has a Coroutine version of the method btw

private IEnumerator Start() {

frigid sequoia
#

Can I make some parameters of a superclass to not show at all on a subclass?

#

Like the basic attack is child of the skill class, since it's easier to take as that for recounts and all, but I don't need it to have all these values, tbh

#

Those are only used for the other skills, and actually just for ease of display, they are not meant to be inpunt in there

ashen arch
frigid sequoia
#

Yeah, I WANT them to show for all skills currently, since I am currently testing that

#

But I don't want to show for that specfic subclass

frigid sequoia
#

How?

cosmic dagger
#

You need to create a custom inspector for that type (class) and manually draw the fields you want to display . . .

timber tide
#

Why wouldnt you use those parameters. Seem like they should apply anyway

cosmic dagger
#

If you need to hide (unused) fields from a derived class, that's a code smell . . .

timber tide
#

yeah, there are situations to hide stuff mostly enum related, but hiding parameters from the parent is odd

frigid sequoia
#

Actually half of those parameters are not even used on the basic attack

#

But it does basically everything else a skill does

#

So, I placed it under the skill superclass

#

Is like.... the most superbasic version of a skil you can have, and lacks a lot of the parts all other skills do have

#

Best way I would place a interface separating all other skills from the basic attack, but, ah, not really much worth it to work on that

#

It's mostly a convenience for me while moving through the components

#

I don't need a cd or cost for basic attacks, it's obviously 0 lol

sour fulcrum
#

sure but those being 0 are an explicit game design choice

#

so arguably they should be seen, no?

frigid sequoia
#

Those are meant to be shown on the description of the skills when chosing the given character, but a basic attack doesn't even show there, so it's redundant

timber tide
#

One idea is abstract the top level and have a skill and attack derived class. Keep the behaviour in the abstract but make the derived fill out a struct of information to pass into the behaviour. Doing this will allow you to expose the variables in the child on the editor for the class that you want.

sour fulcrum
#

you ever just write something like this and start to wonder why english has different formatting for just 1 and 2

        string ending = lastNumber switch
        {
            '1' => "st",
            '2' => "nd",
            _ => "th",
        };
#

i never considered it before

#

i forgor rd πŸ˜”

sour fulcrum
#

return (new List<IDraggable>(ActiveLevel.Draggables) { ActiveCube });
Never used the param and constructor at the same time before, does this code correctly make a new list with the contents of ActiveLevel.Draggables and ActiveCube?

#

just sanity checking

median hatch
#

you mean as in lack of knowledge on how to save data?

#

or too much data to handle

frigid sequoia
#

Probably both???? I dunno

#

I would need to save a pretty good chunk of stuff, but also never done it before

#

I think I do have an idea of how to do it

median hatch
#

never save scriptable objects during runtime tho

#

instant regret

#

they're for static data

#

i use JSON for dynamic data

#

and player prefs for settings like audio graphics etc

median hatch
#

then in your playerdata you save the current weaponIndex

#

you match it with the weaponIndex in your weapons.json file and bam you spawn it during runtime

#

thats my workflow

#

hope it helps

frigid sequoia
#

Ye, by the time I would be doing that I'll have 100% forgotten about what you just said lol, I still have a lot to go through first

#

But I have SEVERAL characters, each one with a bunch of values that need to be saved AND also, equipment for each one, so....

#

Convoluted

median hatch
#

usually you want to build your save system alongside your game

#

otherwise if you have multiple scenes or a big project you'll lose a lot of time debugging

frigid sequoia
#

The idea is that the entities would be loaded from a prefab, you would have to check which entity prefabs the player has on the roster, then for each of them get stuff like the name and idenfiers for each of the equiped items. Eventually a system to save progress on the game like stages cleared or a common inventory should be needed

#

But all that is a issue for future me

#

Tsh, what a loser, that guy

arctic ibex
#

is there an easy way to like, pause a gameobject? i need to temporaily disable two gameobjects and replace them with another, but i need them to keep all their variables and stuff, so i cant spawn new ones.

Specififcally, is there a way to turn of all updates, fixed updates, collision checks ect till another script calls it to "unpause"

verbal dome
#

Worth noting that OnTriggerEnter and OnCollisionEnter will still get called on disabled scripts

#

But not on inactive gameobjects

arctic ibex
verbal dome
#

All of its components get disabled with the gameobject

arctic ibex
#

thankyou!! ill go read the docs, that sounds great!

arctic ibex
#

oh and adding on to that (but less important)
Can the public variables be set by other scripts?

verbal dome
#

It just stops unity messages like Update getting called

arctic ibex
#

thankyou so much for the help!!

rugged beacon
#
    private void Update()
    {
        moveInput =  moveAction.ReadValue<float>();

        if(jumpAction.IsPressed() && IsGrounded())
        {
            isJumping = true;   
        }
        if(jumpAction.WasReleasedThisFrame())
        {
            isJumpCut = true;
        }
    }

    private void FixedUpdate()
    {
        animator.SetBool(moveAnimation, MoveControl());
        if (isJumping)
        {
            rb.linearVelocity = new Vector2(rb.linearVelocityX, jumpForce);
            isJumping = false;
        }
        if (isJumpCut)
        {
            rb.linearVelocity = new Vector2(rb.linearVelocityX, rb.linearVelocityY * 0.5f);
            isJumpCut = false;
        }
    }

is this good idea to divide jump like this? i know that rigidbody goes to fixedupdate? and i think register input should be in update ?

viscid needle
#

can anyobdy reccomend where should I learn c# from?

slender nymph
#

there are beginner courses pinned in this channel. i personally recommend starting with the microsoft one, then going for the pathways on the unity !learn site

eternal falconBOT
#

:teacher: Unity Learn β†—

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

wintry quarry
rugged beacon
#

bet thanks, but when i hold the jump button, the max jump isnt consistent, dont know why

wintry quarry
#

And it's unclear how your grounded check works

rugged beacon
#

like when i just hold jump, some jumps higher than previous ones, that can be from groundcheck? my groundcheck is a gameobject at foot with this: var hit = Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);

#

can it be frame register input stuff

#

make the cut sooner

wintry quarry
#

I think it's what I mentioned and you should debug your code to find out

rugged beacon
#

k i think thats radius 0.2f wonky sometimes

candid garden
#

If I have a game object that starts on 0,0,0 for example, and I have a target, but I only want it to move 0.5 on the X and z axis towards the target, how would I achieve that?

slender nymph
#

assuming you mean you want it to move half a unit total toward the target only on the x and z axes and not half a unit on each of the axes, just get the direction (endPosition - startPosition), zero out the Y axis, then normalize that. after that just multiply the normalized vector by the desired distance (0.5 in this case) and that is the direction and distance to move the object (add it to current position to get desired position)

candid garden
#

Oh true, sorry I meant half a unit on each of the axis. I'm basically trying to offset a position of a grid by half a grid width in both directions but specifically towards the target

slender nymph
#

note that half a unit on each axis is going to result in a greater distance than half a unit from the original position

#

anyway, if you want to add half a unit on each axis then you just need to . . . add half a unit on each axis

candid garden
#

How would I know if it's +0.5 or -0.5 to make sure the end product is closer to the target? If that makes sense

slender nymph
#

get the direction and then just get the sign of each axis, it's just basic math

candid garden
#

I see ty

queen adder
#

If you guys don't know what i'm talking about my player capsule being missing on playtime, this video shows exactly that

queen adder
slender nymph
#

use mp4 to embed videos in discord

queen adder
#

brb

queen adder
#

I'm using Linux Mint and the Linux version of Unity

slender nymph
#

this does not appear to be a code issue, but look in scene view, you'll see it is still there. what is happening is that your camera is likely inside the capsule which only renders from the outside. either that or your camera is simply too close to it to see.

queen adder
slender nymph
#

okay, that does not change anything about what i just said

#

you should consider posting your issue in #πŸ’»β”ƒunity-talk or another relevant channel if you cannot figure it out using the information provided.

alpine summit
#

is there a particular recommendation for how to implement multiplayer? (as for the context of my use case: it's a turn-based board game)

#

it seems like there are several options, so I'm not sure which one would be the best for me

hexed terrace
frigid sequoia
#

Hey, wasn't there a pluggin to preview the color of a hexocode inside the code with a small colored box?

#

It would be usefull now, I am using VS

slender nymph
#

probably, but that's not really a unity question. you can check the vs marketplace for extensions

wintry quarry
#

Rider does it out of the box

idle grove
#

if you find a answer please tell me!

slender nymph
# idle grove im looking for doing the exact same thing
  1. look directly below their message for the correct channel to discuss networking in
  2. you are way too early in your journey to be considering any type of networking. game dev is already hard, making a multiplayer game increases that difficulty a lot
idle grove
#

i know gamedev is hard, im having trouble with a bug without it even being my fault, but you dont need to tell on my face that its too hard for me, i can look around

slender nymph
#

having a baseline understanding of the engine and your needs for the game is kind of a requirement to even understand the different networking options. it's pointless for you to seek recommendations if you don't even know what features you would need

idle grove
#

i didnt expected to join this server just to be greeted with being called uncapable in a pretty language

hexed terrace
#

You're just being warned off from learning networking now. Not ever, and not because of "art".

Box is saying it now because 99.99999999999% of beginners who talk about MP and networking plan to do it now - you're not, you're just grabbing useful info for the future, so, this can all just be dropped.

polar acorn
#

Until you've made something that can at least be considered "a game", you should essentially assume multiplayer does not exist

idle grove
#

also need you in unity talk

hexed terrace
idle grove
onyx jacinth
#

Hello, I'm having an issue with my weapon switching system which is supposed to work side by side with my pickup script.

I can't switch to the other weapon on start (having the fists already enabled) as expected but when the pickup is picked up, I have to do a switch rotation twice before it actually appears and functions.

Like I get the weapon, I try to switch but all it does is disable the fists and doesn't show anything, then I have to switch back to the fists then back to the weapon for it to show.

I've been struggling with this issue for days and nothing on the internet could help me, I even tried with an AI but to no avail.

Same issue persists and I have no idea why, I was thinking it was because my weapon switching system has a variable that keeps track of the previous selected weapon so that you can't switch to the weapon that's already selected but now I'm starting to think it's not just that.

I've tried debugging with logs or forcing the script to activate the weapon twice on selection but nothing helps.

I'm relatively new to Unity and I mainly use tutorials to help me understand and work on my own and this kind of problem just stops me right in my development process.

Here's the weapon switching script and tell me if you also need any more scripts to help you understand, I can provide a video if needed.

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

public class WeaponSwitching : MonoBehaviour
{
    [Header("References")]
    [SerializeField] private Transform[] weapons;

    [Header("Keys")]
    [SerializeField] private KeyCode[] keys;

    [Header("Settings")]
    [SerializeField] private float switchTime;

    [Header("Current Weapon")]
    [SerializeField] private Gun currentWeapon;

    private int selectedWeapon;
    private float timeSinceLastSwitch;
    private bool weapEquip = false;
    private int previousSelectedWeapon;

    private void Start()
    {
        SetWeapons();
        Select(selectedWeapon);

        timeSinceLastSwitch = 0f;
    }


    private void SetWeapons()
    {
        weapons = new Transform[transform.childCount];

        for (int i = 0; i < transform.childCount; i++)
        {
            weapons[i] = transform.GetChild(i);
        }

        if (keys == null) keys = new KeyCode[weapons.Length];
    }

    private void Update()
    {
        previousSelectedWeapon = selectedWeapon;

        for (int i = 0; i < keys.Length; i++)
        {
            if (Input.GetKeyDown(keys[i]) && timeSinceLastSwitch >= switchTime)
                selectedWeapon = i;
        }

        if (previousSelectedWeapon != selectedWeapon) Select(selectedWeapon);

        timeSinceLastSwitch += Time.deltaTime;

        WeaponEquipped();
    }

    private void Select(int weaponIndex)
    {
        for (int i = 0; i < weapons.Length; i++)
        {
            if (weapEquip == true)
            {
                weapons[i].gameObject.SetActive(i == weaponIndex);
                Debug.Log("Trying to switch weapons...");
            }
        }

        timeSinceLastSwitch = 0f;

        OnWeaponSelected();
    }

    private void WeaponEquipped()
    {
        if (currentWeapon.GetComponent<Gun>().equipped == true)
        {
            weapEquip = true;
        }
    }

    private void OnWeaponSelected()
    {
        print("Selected new weapon..");
    }
}

ashen arch
#

Oh, nevermind

#

You're doing that in Select()

#

Do you want weapEquip to be false again if .equipped == false?

if (currentWeapon.GetComponent<Gun>().equipped == true) {
  weapEquip = true;
}
else {
  weapEquip = false;
}
onyx jacinth
naive pawn
#

(just fyi)

ashen arch
#

Yeah, I didn't want to say that yet lol πŸ™‚

naive pawn
#

oh this was adapted from their existing code, didn't notice mb

onyx jacinth
#

Yeah I know it's unnecessary but I wanted to make sure that it wasn't the equipped state causing trouble

#

I just forgot to remove it

final trellis
#

new to the unity input system, how do i have combination inputs?
example: left click does something, but alt + left click does something else

#

cant find anything clear online

alpine summit
#

c# question: I would like to create a dictionary that maps an enum to different subclasses of a generic class, such that I can instantiate a new instance of the corresponding subclass (given only an enum value). Is this possible?

final trellis
#

yip! ( thanks )

night mural
alpine summit
#

ok, fair enough

novel sail
#

Hey, I'm trying to make a top down 2d space game and I want to make a controllable ship with a grid that you can build on. like when you have a building selected it'll snap to a graph then you can place it if you have the requirements and the space. How would I go about making a ship using a tileset that moves, rotates, etc? or the grid eiter. I was thinking that you could make a prefab, tileset for the ship in the prefab. Then create box colliders etc. would this also apply for making modules to add to the ship

brave robin
delicate portal
#

Why is it that my decal projector looks like this in the scene view, but the second is in game view? I don't have angle fading enabled.

novel sail
brave robin
# novel sail Thats a good idea, what would I do for the building system?

If you're looking to drag and drop pieces onto the ship's grid/tilemap, that's also do-able. There's ways to tell what grid cell the mouse is in, googling converting world or canvas coordinates to grid/tilemap coordinates will get you answers on that.
Your build menu would likely be its own separate grid and tilemap of pieces. You could do it also in canvas, but if you're already figuring out how to drag and drop sprites across grid/tilemap then why also figure out how to do it in canvas too.

novel sail
#

Okay, thank you so much

final forge
#

https://paste.mod.gg/zhxwbnniszoj/0
What am I doing wrong with this object pool? When I run this code (the thing that calls the objectpool method is at the bottom of the paste), I get the error NullReferenceException: SerializedObject of SerializedProperty has been Disposed. I like to think its an error with the way the singleton is enforced, but I'm unsure

cobalt depot
#

hey there im brand new to making games especially on unity and im trying to make a bit of a first person shooter and have managed to get the play to move and jump with the inputactions and a charactercontroller and it works pretty well.. the issue im having is that if I transform the player to another position before run time my movement seems to be frozen.. I've even logged the position and it changes but the actual model doesnt.. sorry if this is not even the right discord channel for this and hopefully I could provide enough detail for someone to maybe understand what could be going wrong.. chatgpt also isnt helping lolol

lean pelican
#

Maybe I'm just not understanding the API correctly, but does OnColliderEnter2D also get triggered when an object/collider is instantiated already 'on top'/overlapping another collider? (One of them is a Trigger, the other has a Rigidbody2D)

timber tide
#

And check in awake if it's being set

timber tide
whole osprey
final forge
#

yup they've been added

#

objectpool and entitycontroller are attached to an empty gameobject

whole osprey
#

I mean in your list of pools. Are the gameobjects you assigned in there prefabs or just gameobjects in the current scene?

final forge
#

they're prefabs

timber tide
#

I would think it's some load order problem but you are using start for the other mono. I'd check if the awake is called before you're acting with the pool

final forge
#

Huh, it works after I restart unity

#

This is so weird, is this a common occurence? I changed absolutely nothing

#

other than saving and restarting

whole osprey
#

classic.

I would change your ReturnToPool variable name from gameObject. That is going to be confusing/cause problems.

final forge
#

Yea you're right

whole osprey
#

I don't know. Something maybe hadn't saved like you thought until you manually did it. Hard to say.

final forge
#

ty both of u

eager mesa
#

Ah yes, the universal truth of computing. Restarting fixes most of your issues.

timber tide
#

Ideally bump up the ordering in the settings, otherwise stick your singletons in a load scene to make sure they are loaded first then load your game scene

final forge
wispy spoke
#

Hey! So I tried making a gun which shoots projectiles but somehow the projectiles are waaaayyy too fast - any suggestions?

polar acorn
wintry quarry
#

Change the "force" field in the inspector

wispy spoke
#

it works perfectly now! thanks yall!

ripe shard
wispy spoke
#

yes, true but it works now so imma just leave it hahhahah

wintry quarry
#

assuming the mass of the bullet is 1 then this will be equivalent to that. But yeah it makes more sense to just set the velocity so that doesn't change if you change the mass.

rocky canyon
#

not likely in a #code channel

frigid sequoia
#

How can I unnatach a prefab on scene from the source prefab?

ripe shard
frigid sequoia
#

Oh, with right click

#

I see

final trellis
#

so how do i even utilize the functions OnMove, OnLook and stuff

polar acorn
#

And they'll get called when that button is pressed

final trellis
#

does the script have to reference anything in particular?

polar acorn
#

No, that's what this component does

final trellis
#

awesom

final trellis
#

how do i make this simple function move the _characterController relative to the gameobject's Y rotation?

#

ChatGPT told me to change the last line to _characterController.Move(transform.TransformDirection(-moveDir)); which does work, but we all know how chatgpt tends to be so it might not be it

timber tide
#

you mean the object's forward direction?

final trellis
#

yeah

timber tide
#

transform.forward will give you the direction the object is facing (its z)

final trellis
#

yeah i just always forget what to do with that 😭

timber tide
#

has examples

final trellis
compact sundial
#

hello, I have coded before in other languages but C# is kinda new, i was wondering how to make the character object move while the mouse moves. I already got the basic wasd down, as well as the mouse input and the camera to turn in a 3rd person setup

#

but it wont turn the object so that the WASD changes direction

#

sorry if its a bad explanation

timber tide
#

do you mean SD strafes as it looks at mouse

compact sundial
#

maybe idk what its called exactly

#

its a basic movement I just wanted to ask instead of pouring through docs and google

#

ill try explaining it more

#

basically, when I go forward, it goes one direction

#

and I want it to go whatever direction the mouse is pointing at

#

like if I start looking at one spot and turn the camera right

#

I want the object to turn that way too

#

ik its a really basic problem but I thought it would be faster to ask

timber tide
#

Been a minute since I did a third person, but if you're treating i like FPS controls I think just grabbing the mouseX and rotating on the Y is all you need

ashen arch
#

add a "mouselook" script

timber tide
#

yeah that or a lookat using the mouse raycasting for the direction

ashen arch
#

simple example: ```cs
public class CameraController : MonoBehaviour {
Vector2 rotation = Vector2.zero;
public float speed = 3;

void Update () {
    rotation.y += Input.GetAxis ("Mouse X");
    rotation.x += -Input.GetAxis ("Mouse Y");
    transform.eulerAngles = (Vector2)rotation * speed;
}

}

compact sundial
#

rn I only have one script but once the game gets more complicated, I will add more and more scripts, do you want to see it?

#

I have it ready to paste

compact sundial
#

instead its transform.rotate

ashen arch
#

there's different ways to do it

compact sundial
#

ill just paste the code script

#
using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
    private float speed = 0f;
    private float TurnSpeed = 100f;
    private float xRotation = 0f;
    public float SensitivityX = 2f;
    public float SensitivityY = 2f;
    private Vector3 PlayerVelocityVar = Vector3.zero;
    private Vector2 MoveInput = Vector2.zero;
    private CharacterController playerController;
    [SerializeField] private float playerSpeed = 3.0f;
    private float jumpHeight = 1.0f;
    private float gravityValue = -9.81f;

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

    // Update is called once per frame
    void Update()
    {
        PlayerVelocityVar = new Vector3(MoveInput.x, 0, MoveInput.y);
        playerController.Move(PlayerVelocityVar * playerSpeed * Time.deltaTime);

        float mouseX = Input.GetAxis("Mouse X");
        float mouseY = Input.GetAxis("Mouse Y");

        xRotation += mouseX * SensitivityX;
        transform.localEulerAngles = new Vector3(-mouseY * SensitivityY, xRotation, 0f);

        float rotateX = mouseX * SensitivityX;
        float rotateY = mouseY * SensitivityY;

        transform.Rotate(rotateX, rotateY, 0);

    }

    public void OnFire(InputAction.CallbackContext context)
    {

    }

    public void OnMove(InputAction.CallbackContext context)
    {
        MoveInput = context.ReadValue<Vector2>();
    }
}
timber tide
#

eulers is fine as long as you clamp it below 90 on the tilt

compact sundial
#

I dont really know what im doing, just messing around with the stuff

#

I had a 2 hour game development class today and am trying to practice afterwards

#

we had a bunch of problems before starting so that is all we got done really

frigid sequoia
#

Hey, after the new version of VS I lost like all the references to other scripts that showed on the top left corner. I was using that

#

Could it have lost a configuration on the update or something like that?

eager spindle
#

!ide

eternal falconBOT
teal viper
#

Maybe take screenshot of the whole window, so that it is visible in context.

frigid sequoia
#

I assumed it would reset, but it has... reset like 3 times just today? And I am like... why?

#

I don't know what else do u want me to show lol

final trellis
#

how do i make this input not also invoke OnJump() when releasing the Jump button

jade monolith
#

Hello

#

Someone directed me to this channel to ask for help

#

I keep getting this same error on all my new projects, I tried switching the version and that did nothing

#

Sorry for the bad picture, lmk if I should take another

#

(Or a screenshot lol)

cosmic dagger
jade monolith
#

Thanks

#

Wait

#

Thats where the guy was telling me to come here

#

Whatever

cosmic dagger
#

Yikes. That is confusing . . .

frigid sequoia
#

Why????

north kiln
#

🀷 I'd just switch to another ide. If you're doing non-commercial work you can use Rider for free

foggy spade
#
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;

public class AstroidSpawner : MonoBehaviour
{   [SerializeField]private float timeSpawn;
    public GameObject Asteroid;
    private Vector3 Spawnpos;
    private float SpawnOffsetX;
    private float SpawnOffsetY;
    private float SpawnOffsetZ;
    [SerializeField] private List<GameObject> Prefabs = new List<GameObject>();
    private GameObject PrefabAsteroid;
    [SerializeField] Transform player;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()

    {
        SpawnOffsetX = Random.Range(-10, 15);
        SpawnOffsetY = Random.Range(10, 20);
        SpawnOffsetZ = Random.Range(-20, 20);


        Spawnpos = player.position + new Vector3(SpawnOffsetX, SpawnOffsetY, SpawnOffsetZ);

        timeSpawn = timeSpawn + UnityEngine.Time.deltaTime;
        if (timeSpawn >= 3f)
        {
            timeSpawn = 0;
            AstreoidSpawner();

        }
        Destroy(PrefabAsteroid, 4);

        
    }

    void AstreoidSpawner(){
        PrefabAsteroid = Instantiate(Asteroid,Spawnpos,player.rotation);
        
        Prefabs.Add(PrefabAsteroid);
    }
}

``` everytime i Instantiate the asteroid itll double each time, for example it starts at one then two four eight and it continues
frosty hound
#

You probably have this spawner script on another object as well, such as on the asteroid object you're spawning.

foggy spade
frosty hound
#

Because you're spawning an Asteroid, which itself has the same script, which in turn would cause it (and the one that spawned it) to each spawn their own Asteroid.

#

This process would continue, doubling each time.

median hatch
#

i never knew this...

median hatch
#

what a zinger

#

time to download

deep moss
#

Guys how to do snap zone in unity but not in VR

#

Like i want to do it in third person

frigid sequoia
#

If I have a list A of objects with a parameter param, and a B list of parameters param; how do I check if every item on the list B is contained within the parameters of the list A?

#

Looping list B for each value on List A sounds like terribly slow

timber tide
#

Make a subset of a list and share the reference between the two?

frigid sequoia
#

I think I would have to conver it back anyways, so wouldn't be much better???

#

Maybe I am wrong??

timber tide
#

Not sure of your usecase. Hashsets could also be useful

#

c# hashsets have it all

cosmic dagger
#

What is a "parameter param?" I'm lost . . .

rocky wyvern
#

Some arbitrary value I assume

#

Bro just wants to not do foreach value in list b does list a contain this value in list b

#

Not relevant to the problem what that data is I assume?

rocky wyvern
frigid sequoia
#

UI is using a List of UI elements StatusInfoDisplayer; each of these has a referenced StatusEffect that is displaying, entities have a list of StatusEffect containing all the current status applied. I want to update the displayers in a way that each status on the list of the entity is showing in the displayers and removed when they are no longer there

frigid sequoia
rocky wyvern
#

I would instantiate a prefab for each bit of ui for a single status effect

#

And organise them with layout groups

#

You can easily get something like minecraft style that way

#

Unless it’s actually important that certain status effects show up in a certain position on the screen or the like

frigid sequoia
#

That's... what I am doing? How do you do that without lists?

#

Like I need to hold how many stuff I need to show

rocky wyvern
#

Why does that need to be done in a list?

#

The whole idea of a class based structure is that each status effect could have a reference to its own prefab

#

You can grab that and instantiate it in some ui manager

frigid sequoia
#

Nope, it needs to be updated in runtime, they are not just prefabs

#

What each status shows is modified over time

#

They have a generic prefab for all of the statuses and what they display is modified on the instantiation and over time

#

Like you could have the same exact status but have now 3 stacks of it instead of 1

#

I need those references, is not isntantiate and forget

rocky wyvern
#

Sure so use listeners

#

It’s better to distribute the job of changing the status effect uis to the status effect uis; results in much cleaner solution

rocky wyvern
frigid sequoia
rocky wyvern
#

You don’t need to you can use listeners

#

Orrrr alternatively you have some list of status effects and the status effect ui bits can check vs that list themselves

#

That still solves the issue of needing this list comparison thing

frigid sequoia
#

I should probably use listeners, but seems like I am gonna mess up that and later I am gonna be totally unable to tell what is calling what

#

I would need to call the UI that may not even be active when ANY kind of status effect is applied or modified in any way and then check if it was applied over the selected entity, and then add it to the list of statuses, but they wouldn't even be updated to display the correct info giving how I am handling the intialization.... mmmm....

#

Definelty checking if something needs to be changed when a status is modified is more efficient that rebuilding it anew every X frames but.... I don't think I know how to handle that

rocky wyvern
#

I mean you can absolutely use a list if you find it simpler to implement

#

And when something occurs than needs ui to be changed you just iterate over the list until you find the correct bit of ui and tell it what’s happened

#

And if there isn’t one you need to instantiate one

#

But idk where that list comparison thing fits into that

frigid sequoia
#

I guess I could actually use a dictionary???

rocky wyvern
#

Possible but holding duplicate data is unnecessary

frigid sequoia
#

I have A LOT of "duplicate" data tbh

rocky wyvern
#

It’s ok to check on some class on the ui instead of having it directly correlated in a dictionary it’s not slow or anything

#

And removes any chance of mismatches or desyncing

#

The extra .001ms isn’t worth it

visual linden
#

Couldn't each status instance just fetch their own status from a single source rather than a single source feeding it to each and every status instance? That way, if it's inactive, it's not fetching anything, and you could easily do culling to only fetch when necessary.

median hatch
#

something like turning a bool to true

#

then when you want each specific element to do something you reference that one

#

that way you dont have to go through the list everytime searching for it

median hatch
frigid sequoia
#

I ended using up a very convoluted system with a dictionary

#

I am seeing that I am gonna regret not using listeners in the future....

median hatch
#

youre using a foreach tho

frigid sequoia
#

But I wouldn't even know where to start when doing that

frigid sequoia
#

At least I managed that lol

median hatch
#

yea thats good

#

you can check for C# events

#

everytime theyre instantiated they send their individual index to a centralized list

#

then when whatever you want to happen happens

#

you reach that individual index and do whatever with it

#

ofc i dont know the full context of your code but something like this should work maybe?

median hatch
#

from what im reading each statusDisplay gets instatianted

frigid sequoia
#

Why would I send the index??? You want to give the event an index value it should be affecting or....

median hatch
#

my point is instead of checking on each element if they have or not that status

#

each instantiated prefab would tell you already

frigid sequoia
#

Yeah, I guess I could make the isntantiated displayers check if the status is still running or have been modified, that's true

#

Not sure how much more efficient that would be tho

grand snow
#

Joining late, are these ui views/elements that display a status all looking the same? (e.g. for poision and slow)
I would refresh the whole thing and just re display the current status effects, if it has too many views we just hide the un used ones or make more.

#

If it has a duration the UI view can countdown itself and hide itself but if we refresh it all then that ofc gets updated to the latest state

median hatch
frigid sequoia
grand snow
frigid sequoia
#

I can change it at any point anyways

median hatch
#

then if its good enough its all gucci

#

boa sorte chefe

frigid sequoia
#

Probably I will once I'm in need of those extra frames desperately, which surely is gonna be soon

frigid sequoia
grand snow
#

If effects change this frequently then sounds like it does need to refresh quite often

inland latch
#

why is my event not showing up in my player input events?

public void OnMove(InputValue value)
{
    // Read input from the new Input System
    movementInput = value.Get<float>();
}```
#

the script is on the same object, that's the functions showing under that script

slender nymph
#

if you are using the events rather than the send message option then your parameter is wrong

naive pawn
alpine summit
#

question about events: it seems like invoking an event that isn't connected to anything causes a crash. Am I doing something wrong or is this just the way it is?

slender nymph
#

wdym by "causes a crash"?

alpine summit
#

it causes a null reference crash

#

maybe I'm instantiating it wrong

slender nymph
#

an exception is not a crash. but if nothing has subscribed to the event and this is a pure c# event then it's just null, null check it when you go to invoke it. you can use the null conditional operator ?. for this

alpine summit
#

ah ok, thank you

grand snow
#

I do this for my events: event?.Invoke()

tepid idol
#

!code

eternal falconBOT
tepid idol
#

Any idea why I'm getting this error? ``` NullReferenceException: Object reference not set to an instance of an object
ProfileLevelDisplay.LoadProfile () (at Assets/Scripts/ProfileLevelDisplay.cs:25)
ProfileLevelDisplay.Start () (at Assets/Scripts/ProfileLevelDisplay.cs:15)

#

I've been trying to fix it for a few days but end up breaking my game. I've tried asking AI before I asked here but to no avail.

wintry quarry
#

You simply haven't assigned the usernameText field in the inspector

wintry quarry
#

it is possible and likely you have another copy in the scene somewhere

#

type t: ProfileLevelDisplay into the hierarchy search bar to find it

wintry quarry
#

this isn't even the correct script at all

#

The script with the error is ProfileLevelDisplay so this screenshot is irrelevant

wintry quarry
tepid idol
#

This is the big error I've been breaking my game with.```NullReferenceException: Object reference not set to an instance of an object
DevelopersHub.RealtimeNetworking.Client.Sender.SendTCPData (DevelopersHub.RealtimeNetworking.Client.Packet _packet) (at Assets/DevelopersHub/RealtimeNetworking/Scripts/Sender.cs:14)
DevelopersHub.RealtimeNetworking.Client.Sender.TCP_Send (DevelopersHub.RealtimeNetworking.Client.Packet packet) (at Assets/DevelopersHub/RealtimeNetworking/Scripts/Sender.cs:39)
DevelopersHub.ClashOfWhatecer.Player.Start () (at Assets/Scripts/Player.cs:81)

#

I've also asked AI about this but AI's suggestions just break my game further

wintry quarry
#

If you're a beginner i'd stay awaty from networking for now.

fleet solstice
#

Hello, I hope I'm asking in the right place. Two of these errors pop up every time when I open a script. Even if it is a freshly created script in an entirely new project.

Been racking my head on this for some time now - google suggests launching UnityHub with Administrator privilleges for a similar issue but that does not seem to solve it. Any ideas? πŸ₯²

slender nymph
#

those are warnings, not errors. but you need to go into the External Tools settings in your Project Settings and select your existing code editor as the script editor
!IDE πŸ‘‡

eternal falconBOT
fleet solstice
#

Thanks @slender nymph, worked like a charm. Not sure if there is karma in this server πŸ™Œ

naive pawn
fleet solstice
#

Am I misusing float here, or is some sort of AI misreading this variable's intent? One of the solutions is to make it readonly or to define a constant and assign its value to the variable - but not to assign the value to the variable directly.

What is the reasoning behind this? My goal is to just define a float variable in that script to use/adjust throughout the game.

naive pawn
#

to be clear, it isn't an error or a warning. it's just a suggestion that maybe you want to do that, but maybe not

#

in this case, it's because you never modify enemySpawnSpeed in the current state if of your code

frail hawk
#

a proper float would have a f behind the value

fleet solstice
#

Damn, makes perfect sense! Thanks bunches.

naive pawn
#

but maybe you plan to do that in the future; in which case, you can just ignore the suggestion

naive pawn
wintry quarry
fleet solstice
#

Yeah the IDEs really seeing three steps in the future nowadays! From a relative beginner anyhow. Thanks, peeps.

hot palm
#

!code

eternal falconBOT
zealous geode
#

What would be the best approach to have multiple resources able to be generated? I'm trying an approach with scriptableObjects, and the most, straight-forward thing would be to create multiple prefabs with a monobehaviour script containing the scriptableObject, but, isn't there a way to have a generic resource prefab that receives the mesh (or gameObject) of a resource from it's data and instantiates it on runtime?

wintry quarry
#

The biggest question is what do you mean by generating resources

zealous geode
#

I have a pooling system with a damageable GO on my project, and when it gets destroyed I want it to generate (instantiate) resources.

Referring to the first question, yes, I was thinking of a resource class, a monobehaviour referring the resourceData scriptableObject.

My question refers to if there's a way to have an empty GO with that resource class and, with a factory system or event, it's meshRenderer and collider match the data resource with it's own GO.

If not, then i'll go for having multiple prefabs, each one with it's own resource class and data referring on it.

floral wren
rare pivot
#

can somebody possibly help me understand why my Camera object is not being init properly? I have a main camera under XR origin, and the gyroscope/rotational perspective is working. but my Camera/Camera Manager are never being initialized and they throw errors for being null

jolly stag
#

Having a strange error with the unit 4 tutorial and was wondering if anyone could lend a hand, the if statement is supposed to active whenever all enemies are destroyed but it's not activating. Thank you

    {
        enemyCount = FindObjectsByType<Enemy>(FindObjectsSortMode.None).Length;

        if(enemyCount == 0) // Respawns enemies if count is 0
        {
            waveNumber++; // Increase the variable waveNumber by 1 each time all enemys are destoried
            SpawnEnemyWave (waveNumber);
            numberDebug = true;
        }
rare pivot
#

I have allowed camera permission on the device (Galaxy S10) and I included a permission script

rare pivot
rare pivot
#

np. also you can enable language highlighting with ''' cpp (or other language names) on the first line

rare pivot
jolly stag
rare pivot
#

maybe make a log entry every time an enemy is created

jolly stag
#

And I've found it, the Enemy script has been put on the floor as well from when I was trying to drag drop the script!

#

Thank you for helping me debug this

rare pivot
#

glad you got it man.

#

isnt debugging so fun

jolly stag
#

It's a valuable skill

rare pivot
#

It really is. And it’s very frustrating sometimes but also very satisfying when you finally figure it out. Forces you to learn

alpine summit
#

I have a class that extends ICloneable. Does Clone work "as expected" for subclasses of this class? (i.e. instantiates an instance of the subclass when called)

#

or, must I override Clone in each subclass in order for it to behave this way?

#

maybe I should use my own method for cloning with a generic type? Β―_(ツ)_/Β―

rare pivot
#

you could make a templated Clone

alpine summit
#

can you elaborate?

rare pivot
#

make a function that takes in type <T> and will return a reference to a new object of type <T> ? or just implement Clone in each of your types

alpine summit
#

I'm not super familiar with generic types, is there any way to constrain T to be the class I will be inheriting from (or a subclass of it)?

#

I will need to be able to access its class attributes

rare pivot
#
public void DoSomething<T>() where T : BaseClass```
alpine summit
#

like this, right?

grand snow
#

This can be used to clone some of an object but it wont make a copy of a class ref for you

alpine summit
#

will a shallow copy work with Vector2Int attributes?

grand snow
#

attribute? you mean struct?

#

value types will be a copy

alpine summit
#

attribute as in the class I want to copy has something like Vector2Int pos

grand snow
#

Thats a struct field

#

that will be a copy as it cannot be anything else

alpine summit
grand snow
#

its not possible to have a reference to a struct without unsafe (or if we use a ref function arg)

alpine summit
#

wait maybe this is not enough information, just to clarify I want something like r.pieces[x,y] = pieces[x,y].MemberwiseClone()

grand snow
#

should work just fine if Piece is a class

alpine summit
#

the issue is that MemberwiseClone has a return type of object

grand snow
#

cast it back

#

(Piece)piece.MemberwiseClone()

alpine summit
#

if I cast to Piece, it will behave correctly for subclasses of Piece?

grand snow
#

yes

rare pivot
#

no object slicing in C# is cool

grand snow
#

Remember if Piece has some class ref inside that you also need to clone you need to do this process manually instead

#

e.g. a list

alpine summit
#

hmm ok, the other issue I'm seeing is "Cannot access protected member 'object.MemberwiseClone()' via a qualifier of type 'PieceState'; the qualifier must be of type (class that I'm writing this method in)" on MemberwiseClone

#

oh, I think I see

grand snow
#

(Piece)(pieces[x,y].MemberwiseClone())
use some brackets to make it happy or put the clone into a var firstly

alpine summit
#

based on examples I'm seeing online

#

wait nvm

grand snow
#

its a member function you are confusing yourself πŸ˜†

alpine summit
#

lol

#

yeah I'm just still not sure what the actual problem is

grand snow
#

Ah its protected so you need to add a function to PieceState that calls and returns the result

alpine summit
#

ah ok

#

(and will that also work fine for subclasses of PieceState?)

grand snow
#

protected members can be accessed by the class and sub classes

#

public: everyone!
protected: only me and my kids
private: ONLY ME

alpine summit
#

yep

#

the main thing that confuses me is how class inheritance interacts with inherited methods :P

grand snow
#

you will learn it with time

alpine summit
#

seems to work (for now), thanks for the help BlobHeart

grand snow
peak timber
#

Does anyone know how to fix it by not getting the text deleted every time I type a letter and the front letter keeps deleting? I don't know if you understand what I'm saying, but I hope the video will make you understand

zenith cypress
#

Press the Insert key on your keyboard, you are in replace mode

peak timber
#

ohhh thank you!

lean pelican
#

I have some prefabs (that get instantiated, so I can't do it via the editor) and I want them to add a Listener to an Event of theirs inside Start(), but I keep getting this error instead.

#

 protected override void Start()
 {
     base.Start();     
     hazardCollision.AddListener(GameObject.FindWithTag("Player"). GetComponent<PlayerCollision>().CollideHazard);
 }```
#

And in PlayerCollision
public void CollideHazard(HazardType type, int score)

#

HazardType is an Enum.

#

I did pretty much the exact same in another game, and there it worked just fine, what am I missing here?

cosmic dagger
# lean pelican

which line is 15 (the error line) for both of those scripts?

lean pelican
#

The one in Start() that actually tries to add the Listener.
hazardCollision.AddListener(...

#

This one.

wintry quarry
cosmic dagger
#

Did you check to ensure none of the references are null?

wintry quarry
#

I got bamboozled by the space between the . and the GetComponent, I thought those were two different parameters

frigid sequoia
#

Nulls should not return the out of range exception, should return the null pointer exception, wouldn't they?

#

Out of range may be cause you are trying to pass an enum value that does not exist????

cosmic dagger
#

It says it's not in the expected range. That's a bit different from an actual out-of-range exception . . .

wintry quarry
cosmic dagger
#

You should break that line into multiple statements for readability . . .

#

The error should give you the exact line to narrow down if it's the FindWithTag, GetComponent or AddListener . . .

lean pelican
#

The HazardType is correct. It's not finding the Component.

frigid sequoia
#

Ye, usually when you have a lwith multiple ".", meaning the get references inside references returning errors, you usually want to check each of the parts one at a time

frigid sequoia
high summit
#

okay so had a weird issue but figured out why it's happening, The X and Z value in this case '0' should remain untouched

#

so i need to somehow pass it the existing x and z value that the object drawer already has

wintry quarry
#

Or rather

#

.localEulerAngles

#

since localRotation with give you a Quaternion

high summit
#
drawer.transform.DOLocalRotate(new Vector3(drawer.transform.localEulerAngles.x, openvalue, drawer.transform.localEulerAngles.z), 1f, RotateMode.Fast);
#

so something along these lines?

wintry quarry
#

yes

#

though it would be slightly more efficient to use an intermediate variable here (or two)

lean pelican
frigid sequoia
# lean pelican How do you mean? Main component on what?

If you have a player type of script, and you KNOW you are gonna be calling the player collision over and over from different places, you may as well create a new variable on the player to slot the collision in, so you just need to get the player.collision instead of going throught the GetComponent, which is way slower and can also return issues that hard to see like the one you are having

#

That's what I do at least

lean pelican
#

I see, good point.

high summit
lean pelican
#

I think in this case the issue was actually something else entirely.
Because is it possible for GameObject.FindWithTag to find a child Gameobject with the tag first instead of their parent GO?

#

Because it wasn't finding any of my other components either, but by using GameObject.Find with the name, it works.
The lack of children that share the tag would also be the difference to that other game I did the exact same thing, where it did work just fine.

wintry quarry
rare pivot
#

guys, if i want to write a default script that runs every update, should i attach it to an arbitrary object, or is there a way to create a scripting only object?

wintry quarry
#

you could write code that spawns such an object, if you wish, but it's pretty simple to just create the object in the scene

wintry quarry
#

If you used ECS you could create those "scripting only" objects (they're called systems), but ECS is a completely separate and complicated beast, which it's not worth diving into for something this simple

frigid sequoia
#

Are you sure your parents does have the tag???

rare pivot
#

maybe attach to the camera I guess?

wintry quarry
#

don't put it on the camera

rare pivot
#

okay

lean pelican
frigid sequoia
rare pivot
frigid sequoia
lean pelican
#

Not 'random', apparently arbitrary, but consistently.

frigid sequoia
#

Yeah, probably solvable, but I would just advise you to make the player a singleton, so you can inmediatly get it without any tag to search for

high summit
#

Not sure if the issue is in code so i'm gonna put whats happening here because it probably is,

This draw is being specifically weird, this is it's default rotation

-180,0,0

#

So i set it's closed values

#

this is it's open value

wintry quarry
high summit
#

I could to that yeah

#

but yeah when I open this door

#

it flips on it's head

#

and I have no idea how or why because i'm just changing the y value

wintry quarry
#

what's that about

high summit
#

It just seems to be how this model came

wintry quarry
#

well it's going to mess with all kinds of calculations

high summit
#

Oh, i'll copy and flip the other door and try and see if that helps

wintry quarry
high summit
#

Yeah i can't copy the other door it's not modeled to allow that

#

with the handle placement

frigid sequoia
#

Why not just animate it instead of hardcoding it?

high summit
#

I'm liking learning how to tween πŸ™‚

#

plus from reading, animating lots of simple things like opening a draw is somewhat overkill

high summit
wintry quarry
high summit
#

Left door is scale 1 and the right door is scale -1

wintry quarry
#

If you need to rearrange the hierarchy a little bit to achieve that, it may be worth it

high summit
#

and my script seems to work fine on those

#

I'm just wondering why it would be any different on the top

#

I must have overlooked something

#

Fixed, a default position was set to -180 instead of 180, not really sure how or why but all good now

fleet solstice
#

Problem πŸ€”. I want to make a 2D monster appear to spawn by starting its y scale at 0 and animating it to 1. However if I spawn it at normal size, it flashes in full glory before starting the animation. Meanwhile if I start it squashed - it goes back to being a pancake after finishing 'spawning'.

Is there some obvious solution to this I am missing? Perhaps a way for animations to alter the parameters permanently? Or spawn it already playing the animation? I realize I could alter the scale in accordance to the animation separately, but that feels like a really backwards solution.

timber tide
#

Sounds like this would be a common problem. I would think there's a way to just start the animation at a specific frame on the API

#

otherwise script a way for it to not render until a frame has passed

fleet solstice
#

That might be the way - having the prefab squashed by default feels even more backwards. Thanks!

All I could come up for this late at night was that a 2D sprite is already a pancake. Squashing it flat height-wise rather makes it a french fry.

final forge
#

I'm trying to add object pooling for a bullet (dissapates after a time), but I think the code is a mess. Can someone please give me some tips so I don't lose my mind when I am looking at this stuff in the future? If I were to access the animator here, to set the fireball to detonate after hitting the enemy or exploding after n seconds, would I put that in the Fireball class? What is the "proper" way of doing this? Cuz this looks horrible
`public class Fireball : MonoBehaviour, IPooledObject
{
private float travelTime = 1f;
private float velocity = 15f;
private bool isTriggered = false;
public void OnSpawn()
{
}

public IEnumerator projectileSpawn(Vector2 unitDirection, float ChargeTime = 1f)
{
    float StartTime = Time.time;
    while (Time.time < StartTime + travelTime && !isTriggered)
    {
        transform.position += (Time.deltaTime * velocity) * (Vector3)unitDirection * Mathf.Clamp(ChargeTime*0.75f, 1, 5);
        yield return null;
    }
}

}

IEnumerator FireballCoroutine()
{
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(new Vector2(Mouse.current.position.x.ReadValue(), Mouse.current.position.y.ReadValue()));
Vector2 playerPosition = transform.position;
Vector2 direction = (mousePosition - playerPosition).normalized;
GameObject fireball = ObjectPool.Instance.SpawnFromPool("fireball", transform.position + (Vector3)direction, Quaternion.identity);
IPooledObject temp = fireball.GetComponent<IPooledObject>();
yield return temp.projectileSpawn(direction, 1);
fireball.SetActive(false);
ObjectPool.Instance.ReturnToPool("fireball", fireball);
}`

timber tide
#

I'd ditch the coroutine and just make an update in your fireball class

sour fulcrum
#

Also just wanna point out that's an unsafe getcomponent

#

Probably fine in how your using it but easy enough to avoid so

final forge
#

Sorry could you explain? im new

sour fulcrum
#

so when you get IPooledObject from fireball, your not checking if that is null or not

#

so if IPooledObject wasn't on it the code would error

final forge
#

Oh I see

#

On the topic of components, If I have an object in my object pool being reused, and if I make a component call like GetComponent<Animator>(), would I have to make that call again when it's made active again?

final forge
sour fulcrum
#

it's good practice to just always check, Unity provides a TryGetComponent function that makes this easy, so eg., you could do


if (fireball.TryGetComponent(out IPooledObject temp))
   //stuff with temp
else
   //yield return null or something similar

Not experienced with pooling so can't help too much with your other questions personally, sorry!

final forge
#

Oh cool

#

thx

sour fulcrum
final forge
#

will do!

sour fulcrum
#

also somewhat nitpicky but if it was enabled it would still return the component. being enabled/disabled is a unity specific thing applied to things deriving from Component/MonoBehaviour but null is a concept c# introduces

final forge
#

oh ya

final trellis
#

im unsure if this is an issue with my code or with how i've set up my inputs

the issue is, is that it seems to jump twice when i press the jump key, and then jumps again once i let go ( when im grounded, ofc ) ( look at the log as the video plays )

#

in the video i just hold the jump key and then let go once i hit the ground

#

i want to make it not do the weird double jump thing, and also not activate when i let go of the key

timber tide
#

Ideally you want to add some cooldown on the jump, maybe a few miliseconds or two as your collider may still be touching the ground before you're considered non-grounded

#

For the button release problem, I'm a little rusty on that input system but you need to specify somewhere to trigger only on press

#

Try this in your statement there:

if (ctxt.performed && _isGrounded)```
final trellis
timber tide
#

You aren't manually subscribing to the events because you're doing it in the UI, so basically you're getting callbacks for every action. So you need to specifically figure what callback you're getting.

frigid sequoia
#

Hey, can I have like... I way to like... totally replace an object from another?

#

I have kinda of a complex UI element that changes on each scene, but it's inside of an UI that is persistent throught scenes, so the ideal would be having a prebuilt one, that replaces the old one on scene load

final trellis
timber tide
#

You're getting both started and performed callbacks probably, but you only need one of those. If not performed then try started

final trellis
#

alright, yeagh, adding that fixed both problems, thanks! :3

mossy jasper
#

Idk what i did, i followed what the tutorial said

polar acorn
#

!ide so you don't make spelling mistakes in the future

eternal falconBOT
mossy jasper
polar acorn
mossy jasper
#

honestly, idk

polar acorn
#
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 186
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2025-05-16
mossy jasper
#

nahhhhhπŸ’€

#

sooooo, im guessing im part of the 186 people

polar acorn
#

Yes

mossy jasper
#

dang...

polar acorn
mossy jasper
#

ima give you an update tommorow bc its 12am for me

frigid sequoia
#

Is anyone able to explain to me what is the highlighted line actually doing? I am trying to understand this thingie cause seems useful lol

timber tide
#

few operations that could otherwise been an extra line or two but the devs love saving line space

naive pawn
frigid sequoia
#

So I can just remove all the "?" checks, cause that's a static method that is always there and filled with values

naive pawn
#

i suppose, yeah

frigid sequoia
#

Is this right then?

naive pawn
#

but imo this would be cleaner with a map if possible

frigid sequoia
naive pawn
naive pawn
frigid sequoia
#

So this?

frigid sequoia
# naive pawn a `Dictionary` in c# terms

I was using a static class that just holds references to colors and icons I am using for texts, so if change any, they change all automatically, but now I need to do that from a textInput in editor to save some prefabs, so I cannot just interpolate the string to call those values from there, how should I handle this then?

charred spoke
#

This is the reason ScriptableObjects exists

naive pawn
frigid sequoia
frigid sequoia
charred spoke
#

I think you are confusing the term interpolate here. You want to read a color value and use it in the editor correct ?

#

Presumably you are making some sort of UI theming system

frigid sequoia
#

Basically I want to be able to do this kind of formating but to work on editor

#

Well, not on editor, but the string that I pass in the editor to do an "interpret pass" so it gets the right values before passing it to the TextMeshPro

naive pawn
#

so poor man's interpolation basically

frigid sequoia
#

I guess I am a poor man, yes

naive pawn
#

lmao i didn't mean it like that

#

it just means a recreation of the feature when the actual language feature isn't available

naive pawn
frigid sequoia
#

I want to check for stuff like {healthColor} on the text, and translate that to the value of the healthColor on the TextFormating, so I am guessing what you mean I do a dictionary where {healthColor} is a key and the value is the value of the textFromating.healthColor and do the same replacement there

naive pawn
#

right

#

also with this if you use a serialized dictionary you could modify it from the editor without having to recompile

frigid sequoia
#

I would... have to copy each of the values manually on the editor whenever I change them then....

naive pawn
#

wdym by that?

#

you'd still use a single source of truth, it'd just be in a different place

frigid sequoia
#

If I decide I no longer want [armorColor = "<color=#FFFF00>";], if I serialize the dictionary I would have to change the value there too, not only in text formating

naive pawn
#

same thing with the static fields though?

frigid sequoia
#

I am saying I would have both, not that the static wouldn't need to be changed lol

naive pawn
#

why'd you have both though

sour fulcrum
#

ngl the suggestion i posted yesterday kinda seems like it does all this, aside from additionally defining how to encompass a specific region of text inside the string via an arbitrary interpretation sign

frigid sequoia
#

Cause getting the references would be harder from a dictionary than from a simple standalone parameter

sour fulcrum
#

the scriptableobject dictionary one

naive pawn
frigid sequoia
sour fulcrum
naive pawn
naive pawn
sour fulcrum
sour fulcrum
frigid sequoia
#

It's fine

naive pawn
frigid sequoia
#

I am gonna format based on the TextFormating class, but that class is not gonna be changed, it's just, basically a SO already, it does nothing but to store values

naive pawn
sour fulcrum
#

not directly a critiscm or anything but you come in here asking about the best way to do things a lot and a majority of times you prefer doing not the best way to suit your pre-established preferences. This isn't a problem in itself or anything but it might be worth considering that approaching the question with the intent to find the best solution might not be the most productive way to illicit the answers your looking for

frigid sequoia
sour fulcrum
#

it's a Object so ye

naive pawn
#

the same way you did here lol, with reflection

#

but a dictionary would generally still be better DX (and to lesser importance, better perf) than reflection

#

and even better if you serialize it
making good, scalable, flexible systems isn't really something you can put off. it's way harder to shoehorn them in later

frigid sequoia
#

That's all I am doing

naive pawn
#

cause I am lacking a lot of knowledge
because you refuse to learn stuff that isn't immediately obviously applicable lmao

#

your words, not mine shrugsinjapanese

frigid sequoia
#

Okay, so... do I turn this into a SO dictionary??? Like, I don't even know how to do that, or not even if that's gonna actually help

#

But sure

sour fulcrum
#

Forsure, Don't take that message as combative or anything. I just mean that a lot of the best ways are going to require learning and work and the answers you recieve reflect the question you ask, not neccasarily the reason why your asking the question, if that makes sense

naive pawn
sour fulcrum
frigid sequoia
naive pawn
#

so you basically just stated ignorance of it earlier lol

frigid sequoia
#

I wouldn't know how to actually do that lol

sour fulcrum
#

In my implementation yeah

#

I gave you the code too πŸ˜›

#

This doesn't exactly do what you are looking for as you wanted to define full coverage of aspects of the text inside the text itself

#

This is also not perfect πŸ˜…

frigid sequoia
naive pawn
#

that's exactly what im referring to

#

it's not that it's not modular lol

#

welp, can't make a horse drink. if you don't like getting advice then this discussion is useless lol

frigid sequoia
sour fulcrum
#

you can return type on functions

#

that conceptually could not be limited or restricted to an SO, or class

frigid sequoia
naive pawn
#

it's not flexible or future proof and it splits your workflow terribly (in comparison to what it could be)

frigid sequoia
frigid sequoia
sour fulcrum
#

Oh right that function is something i made up, I assume you have a similar implementation

frigid sequoia
sour fulcrum
naive pawn
#

look man we're giving this advice for a reason
someone else, sometimes outselves, has already gone through the pain of inflexible code or an indirect workflow
we're telling you this stuff so you can learn the easy way instead of going through the process of fixing preventable issues yourself

frigid sequoia
#

Sprites that I assign as a default value on scripts only apply if added on editor, not in runtime for some reason

naive pawn
#

yes, that's what they say they do

frigid sequoia
#

This thingie, I tried going out of my way to keep it on editor only, and it happens, nope, when you call to add that component, it loses the sprite reference 🀷

#

So.... having all in editor is clearly a no-go

naive pawn
#

Default references will only be applied in edit mode.

naive pawn
sour fulcrum
#

also more or less the exact purpose of scriptableobjects πŸ˜„

frigid sequoia
#

So I have to make a prefab of every single script that is ONLY that script to keep the reference?? That seems basically doubling the space it takes for no real reason

naive pawn
#

AddComponent really isn't used much in my experience thonk

#

the space it takes? why is that a concern at all lmao

frigid sequoia
#

Cause I don't want duplicated stuff and then getting all confuse with what is what

naive pawn
#

if you want every instance of a script to use the same references, why not have them in some centralized place

frigid sequoia
#

Isn't that the thinking for the future you say I don't do?

sour fulcrum
#

eg. for a card game prototype my individual cards look like this (im in debug inspector to remove some of odin inspectors irrelevent fanciness)

then i just instansiate a cardbehaviour and give it this data reference

#

then the specific hero the card uses w/ a sprite ref like you we're looking for is in another so

naive pawn
#

or if you want it to be overridable, that's kinda what prefabs achieve

sour fulcrum
#

another fun example of a more advanced implementation

frigid sequoia
#

I want that script to ALWAYS have that image. How would I do that?

naive pawn
#

oh yeah while you're here, before i forget; you still haven't answered the last question i asked in #πŸ“²β”ƒui-ux, i still have a partial impl (partial because im not sure what exactly the constraints are) of your question in a test project lol

sour fulcrum
#

these are the so's that i give to a prefab yes. the idea is to develop a kind of sibling relationship of the prefab that does things and the scriptableobject that has the values the prefab uses

sour fulcrum
#

overall

frigid sequoia
#

Cause I have tried to see the use for SO a bunch of times, but I don't really get in what they are better from an actual script

sour fulcrum
#

i think to an extent it's abit of wording/incorrect perception in your head about the word script

#

a script shouldn't really do or have anything

#

it's a blueprint/template

#

an instance of a script (which when working with Unity is usually a prefab) is what does things

#

so if you want an instance of that script to always have that image, you put it on the instance (prefab)

#

if you want to separate your doing things and knowing things in order to make your code more modular and maintainable, you would put the image on a scriptableobject the prefab looks at

frigid sequoia
#

But... can I even AddComponent with a prefab?

#

Cause that's basically how this works

#

You add it to the stuff when called

naive pawn
#

feels like could be restructured to be a child instead of added directly to the object

sour fulcrum
# sour fulcrum if you want to separate your doing things and knowing things in order to make yo...

the kinda theory behind that sorta goes into the overall responsability of what your things should do.

You need your instance of the script (im gonna call it a prefab) to know about the sprite in order to render it right? But that doesn't necessarily mean the prefab should be responsible for owning the sprite. The prefab does things. If it needs to know something about what its doing it can ask it's scriptableobject for that, because the scriptableobject's job is not doing things, but knowing things

naive pawn
#

more obvious composition of separate parts

frigid sequoia
naive pawn
#

you don't need to worry about that

sour fulcrum
#

Respectfully you do not know enough about c# or unity to be able to care about that level of optimisation

naive pawn
#

unless it's a critical position, readability and maintainability trump performance or efficiency

sour fulcrum
#

Like if you need to care about that you need to learn a lot more in order to exist in a workflow that can solve those problems to that extent

frigid sequoia
#

I am trying, and absolutely failing, to keep stuff optimized since I am aiming for scalability later, having one child would be no issue, but what if I later want to add like 20?

naive pawn
#

still, no issue

#

you start getting issues in the thousands or maybe millions

#

don't worry about optimization until it becomes necessary

#

you can preemptively do stuff in a non-insanely-costly way, but don't worry about it

#

that'd be called premature optimization

sour fulcrum
#

(Especially because the solutions to scalability are usually not super simple and up being a lot harder to iterate off of)

frigid sequoia
#

Not sure if changing the whole structure to work as a prefab chidren instead of components would be worth to fix that tho

#

So @sour fulcrum should I turn my TextFormating static into a S0 that can get a string passed and return the translated formating?

alpine fog
#

Generally you should use SOs for data that's same for multiple instances of a script.

For example you have a SpellData SO that contains the spells name, sprite icon, cooldown, mana cost etc

Now you have your Spell component itself which has a SpellData field. Since AddComponent literally just adds a component, the fields in the component will be empty.

Make a method like AddSpell to which you pass a SpellData and a gameobject, it calls addcomponent and assigns the spelldata field to the SO. With this any code inside the Spell can just check its data from that SO and you don't need to assign things in code

frigid sequoia
alpine fog
#

it's up to you how you want to do it. Prefabs are fine they're just for that, so you don't need to initialize them in runtime. Components however if not prefab-ized to another GO, you will need to set them up manually, that's why using a SO for them might be better in some cases. For spells, I'm using components and a spelldata. Here you can see that I'm actually reusing the same component for different spells (as the SO holds what kind of cast is used, what projectile to shoot and what attack to fire)

alpine fog
# alpine fog it's up to you how you want to do it. Prefabs are fine they're just for that, so...

this way I just have this code on my NPCs/Player and by holding a database of SpellDatas I can give a spell to things with 1 line

public virtual void LearnSpell(SpellData data, bool autoSelect)
{
    if (HasSpell(data))
        return;

    var type = data.Type == "" ? typeof(BaseSpell) : Type.GetType(data.Type);
    
    var spell = (ISpell)thisGo.AddComponent(type);
    spell.SpellData = data;
    spell.Owner = this;
    spell.ObjectID = Guid.NewGuid().ToString();
    
    Spells.Add(spell);
    
    if (autoSelect)
        SelectSpell(data);
}
frigid sequoia
#

It depends on how many spell effects you can fit on the same component for different spells with just SO

alpine fog
#

if you keep the effect object separate from the spell object itself, you can instantiate any effect for any spell. That's essentially what I'm doing by separating cast/projectile/attack as those are created when you fire the spell

frigid sequoia
#

I was actually just using Interfaces/superclasses for that same thing you are doing

alpine fog
frigid sequoia
#

And you are adding these as object or as components?

alpine fog
frigid sequoia
#

Cause adding it as a object I just... go back to the same question, how is that better or worse than a prefab with it's parameters already configured?

alpine fog
#

SOs are not a component and not a gameobject. You can't put them inside a scene - only reference their file

sour fulcrum
alpine fog
alpine fog
sour fulcrum
#

how much is a bunch? seems like in your case that function might not be running often

frigid sequoia
sour fulcrum
#

but if something like this was happening a lot more

alpine fog
eternal needle
#

honestly i don't really consider that the best example of using SOs. The only thing it's showing off there is adding a component based on a string value. Sure it works but you aren't really showing off how SO's are actually used as data containers

frigid sequoia
#

They could be components attached to an object with nothing more 🀷

alpine fog
alpine fog
#

I have 11 different NPC types right now

sour fulcrum
#

not types

alpine fog
#

amount of NPC instances? I have made hundreds of them fight but I don't see the point of the question

sour fulcrum
#

i was curious about the scale of that functions usage since afaik ideally you want to avoid gettype calls at scale (and casting too9)? but a lot less so)

alpine fog
frigid sequoia
#

Quick unrelated question, OnValidate applies whenever you change ANYTHING on the inspector or just checks for the values of the script that has the OnValidate?

eternal needle
# frigid sequoia Cause adding it as a object I just... go back to the same question, how is that ...

the main use case is just as a data container. In terms of the end product you make, it is not better or worse. It is just better in terms of organization.
If you have many prefabs that want the same data, you can modify that data in 1 place (the SO) rather than going back and editing each prefab. I don't really think this is a major use case though. The best part IMO is that it is an asset. You don't need to look through an entire prefab to see the fields you want to edit. It's miles clearly as to what was actually changed in version control too, which you're surely using

eternal needle
alpine fog
#

how is this not a good example of how to use SOs as data containers?

sour fulcrum
#

Why reference a type via string and add it at runtime rather than just spawn a prefab of that type?

frigid sequoia
#

But I kinda like to check where the stuff that I am changing is actually allocated

#

Maybe I change my mind after doing it 10000+ times

eternal needle
#

as long as you're just using it as a data container, you really cant go wrong. If you start following random youtube advice like using it for events then it becomes an issue

timber tide
#

SOs a poop. All hail prefab inheritance

alpine fog
# sour fulcrum Why reference a type via string and add it at runtime rather than just spawn a p...

for prefabs, that's fine. I have objects (like boxes) in the map that are just dragged into the scene but are also able to be runtime created by the SO with the prefab it holds
for components like spells which NPC datas can hold. The base type (which is just empty in SO) is used almost all the time. If I end up needing to write custom code for a spell I will have to reference it via string in the SO for instantiation. Design-wise? that's a bit eh, I should make a propertydrawer which lets me just select the custom type to use for the spell instead of typing in a string for the type. Ofc I can turn this into a prefab but then I'd have a GO for each spell which I don't see a reason for doing so.

Either way, this has allowed me to pretty much only modify what I need without needing to change it all for other prefabs, so the SO does it's job fine. Learning spells, creating npcs, objects, etc is all done via runtime according to SO definitions, npc spawners etc so in my case this setup is great and I wouldn't remake it unlesss it did get me stuck somewhere

hidden marten
#

whats the best way to stop sliding down a slope while idle?

#

like when im not moving, i slowly slide down if i am on a slope due to gravity, how do i make it so i dont slide?

eternal needle
#

uncheck the useGravity field and apply the downward force based on your conditions

frail hawk
#

and for the slope detection i would use the normals of the surface

hidden marten
hidden marten
eternal needle
hidden marten
eternal needle
# hidden marten hmm even if i make my own gravity how will it stop the issue? my condition is st...

I find it much easier to just control the gravity overall rather than selectively enable it. If you achieve the same result by toggling useGravity then go ahead. Im just saying that it isn't too much work.
Nothing about it is related to being idle. Do you want the character to ever so slightly be pushed down the slope while they're also going up? If you only disable gravity when on a slope AND idle, then while on a slope and moving gravity will still affect them, which is inconsistent. It might not be noticeable, but it doesn't make sense to do

hidden marten
eternal needle
#

that issue still exists, it may just not be noticeable in your current setup. if at any point the player can move faster, it'll be noticeable again

hidden marten
hidden marten
eternal needle
hidden marten
eternal needle
#

well i havent seen the code, but from what you're describing it really seems like every individual feature doesn't work entirely. Some other feature is just slightly correcting the issues or it isn't fully noticeable yet

#

even on a small scale, you still have the issue that while moving up a slope, gravity is trying to force you down when it shouldnt (since its not forcing you down when idle either). And you have this because of another issue where your movement doesn't align with the slope. Somewhere along the way you are also using drag, im not sure for what here

burnt perch
#

In Unity2D, I'm trying to move two UI elements around, one child and one parent, but I wanted the child to only appear in certain places of the screen, while the parent is always appearing. I tried using masks, but I want to be able to move both child and parent together always, and if I use a mask, I'm forced to make the UI element I want to hide most of the time, a children of the mask, meaning I either stop making it the child of the other UI element OR the mask be a child of the other UI element, so it would move together and be pointless

fair shore
#
{
    private GameObject[] newpiececlones;
    private Piecesinventoryscript piecesInventory;

    void Awake()
    {   piecesInventory = GetComponent<Piecesinventoryscript>(); 
        newpiececlones = piecesInventory.piececlones;*
    }```
what is null or "not set to an instance of an object" in the * line?
naive pawn
#

you tell us

#

ah, it's piecesInventory then

#

so the object doesn't have the script you're trying to get

ashen violet
#

Hi, I have a script with a serializable string. I set the value in the inspector, the value remains even during runtime, but for some reason when I try to use it, it's empty.

#

oh, nvm im stupid, I saw the problem

queen adder
#

Heya folks

#

I've switched over from Godot and unity is an experience to say the least - can anyone tell me how I would change this setting?

wintry quarry
#

Edit -> Project Settings -> Player

summer forum
#

can someone please help me with smth, im learning unity and i js want soemthig to display on my console but it just doesnt. The conde is fine cus it basically js printing hello. the script is attached the an object, its in assets. I dont get why its not working

slender nymph
#

if your log is not printing to the console then that code is not running

sour fulcrum
#

assets is your toybox

#

not whats out being played

summer forum
#

so what do i do

slender nymph
#

well if it is a component it must be attached to something in the scene. beyond that, you've not provided enough info

summer forum
#

also one thing that i noticed is that Debug.log stays white so i think they are not inherited properly

summer forum
slender nymph
eternal falconBOT
ashen arch
summer forum
ivory bobcat
#

Are there errors?

summer forum
#

here it is

ashen arch
# summer forum

Is that object in your scene and enabled? If your console is not showing anything, then your Console might be configured to filter certain messages. Check the buttons on the top of console window

ivory bobcat
#

Is the script saved?

summer forum
summer forum
#

omg

#

i had to resave it for it to take the changes

#

sorry for the trouble

ashen arch
#

and Visual Studio Editor package installed in Unity?

acoustic belfry
#

Hi, i been wondering

how i can make that for example, an script base has a function, and i want a inherited script to use the same function but with changes, do i have to write the same part of base function too?

slender nymph
slender nymph
acoustic belfry
# slender nymph make the base method virtual, then override it in the derived class then you can...

but i mean, i want it to follow to only some specific parts

like my damage function

this function in the base causes the Actor to lose the needed values of health, deploy some items following a value, BUT ALSO, displays a dead animation and a dead sound along spawning the enemie's shards, wich is a gameobject with lil sprites with collisions

the thing is, i want all enemies follow the basic things like the damage and etc, but i also want it to deploy a custom animation, custom sound, or have some tweaks if needed, like if the damagetype is 1 for example, nothing happens

so thats the thing, how i can make it follow the function but with tweaks?

slender nymph
#

well a lot of that is simply just assigning different values to variables. and if you need even more modularity then you probably need to split the method up into multiple methods

stray oyster
#

Hi, I am new to unity. For 2d games, is there a way (scripted API call) to move and rotate loaded scenes relative to each other when multiple scenes are loaded? For example, I want one scene to be on the right exit in one game state but in another game state I want the scene to be on the bottom exit. I don’t want a scene transition where it jumps to each room. I liked this tutorial but need to be able to move each scene https://m.youtube.com/watch?v=6-0zD9Xyu5c

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH

For this Unity tutorial, I wanted to build off the last tutorial that covered data persistence and loading transitions. This ...

β–Ά Play video
rocky canyon
#

you'd basically just move all the gameobjects within that scene to move the "entire scene"

stray oyster
#

Ok, thanks. I had this misconception that each scene had some relative origin and I could place origins relative to each other

#

I figured would need to transform the objects anyway to β€œrotate” a scene

rocky canyon
#

nah, if u load 3 scenes together. they're all using the same origin world origin (0,0,0) or (0,0) if 2D

rocky canyon
#

should rotate all the objects (if they have good scales and pivots)

calm sierra
#

hi! im on a low-end machine and i got this error when trying to start my game. why? i cant start it again because it saws i need to resolve it first, but there is nothing to resolve, it just ran out of memory

#

right?

rocky canyon
#

appears that way. never seen the error but thats my guess from just reading it

calm sierra
#

where do i turn off Input System package? im trying to look for it but cant find it

nova vapor
#

hi , i am doing this course by gamedev.tv

so after doing the prefab lecture and adding prefabs,

my projectlie stopped destroying itself after collision
can someone please help me

cosmic dagger
#

In the DestroyWhenReached method, you check if the positions are equal. That will likely never happen . . .

nova vapor
#

its the script i added to my projectile

cosmic dagger
#

You need to check if the distance between both positions are below a certain threshold, like 0.5f . . .

slender nymph
#

there is quite a bit wrong with that. for one thing it doesn't do anything at all about collisions. for another, it only ever gets the player's position at start so if the player ever moves after that it won't do anything about it

nova vapor
nova vapor
naive pawn
slender nymph
cosmic dagger
nova vapor
nova vapor
slender nymph
#

it won't destroy itself unless that condition you set is true. so if its position is not the same as the position that the player was in when this object was spawned, then it cannot destroy itself

#

unless you provide literally any other information, that is all that can be said about it

nova vapor
slender nymph
# nova vapor

consider not maximizing the game view so you can actually see the hierarchy during play mode and can actually inspect what is happening

nova vapor
#

His disappears on impact
While mine doesn't
Same code line to line

slender nymph
#

also you do realize that you couldn't record the video with OBS due to the anti-piracy protections, right? you are not allowed to share any part of the course

nova vapor
#

It worked for me as well
Till the point I converted the sphere thing into a prefab

nova vapor
#

Sent it just for reference

slender nymph
#

rather than just keeping it in mind, do it

frigid sequoia
nova vapor
frigid sequoia
#

Oh, I see, well, first step when something doesn't seem to work is to check if it's actually being called at all

#

Above the if do print(transform.position + "//" + player.position); to check both positions on console

nova vapor
nova vapor
# nova vapor

There

I need the object to disappear as soon as it reaches that position
And just stay there

slender nymph
#

inspect the objects instead of ignoring them

nova vapor
slender nymph
#

yes the projectiles. instead of just looking at them in the game and pretending neither the hierarchy nor inspector exists, you can select them in the hierarchy to view them in the inspector and perhaps get some insight into what is happening

frigid sequoia
#

I must say, if your way of leaning is watching tutorials and blindy copy what they do without actually undertanding why it works and scream at the screen when it doesn't work just to repeat the same thing expecting it to work this time, you... are not gonna learn much...

#

Saying that as an advice, not criticism

polar acorn
nova vapor
nova vapor
nova vapor
polar acorn
#

So, get the distance, and check if that distance is less than some small value

#

Rather than checking if they're exactly equal

nova vapor
#

is it something to do with prefabs? cuz it stopped working the moment i turned them into prefabs

polar acorn
#

From what you've shown it appears to be related to numerical precision. You could also add some logs to see what those values are and if they're what you expect

wintry quarry
#

e.g.

if (Vector3.Distance(transform.position, playerPosition) < 0.1f)```
nova vapor
#

there i just added the script to a sphere and it worked

#

lemme send the video

ashen arch
nova vapor
nova vapor
# nova vapor

Please ignore the slow speed of the sphere

But it's the same exact script

polar acorn
#

So do the suggestions you've been given to make that luck no longer a factor

nova vapor
#

Found the fix

I just removed it from projectile empty thing (they are called scenes if I am right) and just let them be separate things

#

I noticed the guy didn't have them like that

I did it so that they were organised but probably there is something more to it that idk yet

polar acorn
#

Do you mean the parent object

nova vapor
#

Yeah

Like yk how "create empty"
And then you can keep ur objects under it

frigid sequoia
#

But that's not a "fix"

polar acorn
#

Probably because it's thousands of units away, and therefore introducing floating point imprecision

frigid sequoia
#

It's just luck

polar acorn
#

So you should do the thing you've been suggested to do to remove imprecision as a factor

nova vapor
solemn sable
#

What is the best way to code screen shake without using cinemachine? Would I have to use quaternions or nah?

frigid sequoia
#

Do a Coroutine that gives the camera slightly different positions each frame

cosmic dagger
wintry quarry
cosmic dagger
#

Oh, the options . . .

#

You should try each method and pick the one that provides the best results (depending on ease of use, customization, and scale factor) . . .

frigid sequoia
#

I think I did a superbasic one that took the camera pos and returned a new one with a random +X value on each axis and for Y frames and that's all

solemn sable
#

Thanks for all the feedback

solemn sable
frigid sequoia
#

Decently so, not very smooth tho

#

You could add transitions, but that's a bit harder

#

Whatever you do, just make sure the camera returns to its original pos at the end

solemn sable
#

Yeah, I feel like using vector3.moveto would give a slightly smoother effect than just putting the camera randomly

frigid sequoia
#

Sometimes you just want a violent shake, so no transition can make the trick

#

But yeah, you can make a Courutine that gives new positions and when getting a new one do a loop that moves the camera closer to the new one each frame and...

#

You know, you can add as much as you want, depending on what you are looking for

#

You can always just animate it, which is a bit weird of a method but hey, works

cosmic dagger
compact sundial
#

I cant figure out how to add a jump or gravity to my character

charred spoke
#

In this 2016 GDC session, SMU Guildhall's Squirrel Eiserloh explores the math behind a variety of camera behaviors including framing techniques, types and characteristics of smoothed motion, camera shake, and dynamic split-screen.

Register for GDC: http://ubm.io/2gk5KTU

Join the GDC mailing list: http://www.gdconf.com/subscribe

Follow GDC on ...

β–Ά Play video
compact sundial
#

idk what im doing

#

can someone help me add a jump and gravity to my character

frigid sequoia
#

You have like a million tutorials about a basic controller like that

compact sundial
#

ik but none are working

blazing bay
blazing bay
keen cargo
#

especially for things like character controllers

keen cargo
compact sundial
#

yes it is because the WASD move works

#

although I still cant figure out how to turn the object with the mouse

#

either

keen cargo
#

maybe it's best if you go through the official unity courses first

#

!learn

eternal falconBOT
#

:teacher: Unity Learn β†—

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

keen cargo
#

because there's quite a bit wrong with that script

regal magnet
#

i am very new at unity i get stuck in this code

#

i was shaking when i was trying to walk to a wall so i chance my movement code to playerRb.linearVelocity from transform.translate

#

but now my chacter stop walking after few sec

#

any idea?

wintry quarry
regal magnet
#

walking

#

i press d for example

wintry quarry
#

you press and release?

#

or you hold it?

regal magnet
#

its moves few sec then stop

#

hold

wintry quarry
#

nothing in this code would make it stop

regal magnet
#

after i stop holding d and press a

#

and then d

#

its work again

wintry quarry
#

are you also pressing left shift or space?

regal magnet
#

no when i just start the game and press d its happen but i think dash(left shift) also trigger this stop thing

wintry quarry
#

do you have any other scripts or components on the player?

regal magnet
#

no